jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
720 stars 149 forks source link

Use "dragged" points in Shiny #42

Closed tbenschop closed 8 years ago

tbenschop commented 8 years ago

Hi,

I really like this new package and I'm implementing a graph in Shiny where users can create their own time series with the "draggable point" option from the http://jkunst.com/highcharter/oldindex.html#draggable-points example. I would like to use the "new" datapoints in server.r and also show them in a table. If someone could help me how to return the data points, that would be great.Please find the code below.

Many thanks, Tim

server.r:

data(citytemp, package = "highcharter")
   function(input, output) {
 hcbase <- reactive({
   # hcbase <- function() highchart() 
   hc <- highchart() 

   if (input$credits)
     hc <- hc %>% hc_credits(enabled = TRUE, text = "Highcharter", href =    "http://jkunst.com/highcharter/")

if (input$exporting)
  hc <- hc %>% hc_exporting(enabled = TRUE)

if (input$theme != FALSE) {
  theme <- switch(input$theme,
                  null = hc_theme_null(),
                  economist = hc_theme_economist(),
                  dotabuff = hc_theme_db(),
                  darkunica = hc_theme_darkunica(),
                  gridlight = hc_theme_gridlight(),
                  sandsignika = hc_theme_sandsignika(),
                  fivethirtyeight = hc_theme_538(),
                  chalk = hc_theme_chalk(),
                  handdrwran = hc_theme_handdrawn()
    )

    hc <- hc %>% hc_add_theme(theme)
  }

  hc

})

 output$table <-renderDataTable({
   #Output from graph
   data.table(month=citytemp$month,berlin=citytemp$berlin
              ,berlin_dragged=citytemp$berlin)#Here I want to use the dragged data. something linke input$highchart$... should do the trick I guess...
 })

output$highchart <- renderHighchart({

data(citytemp)
highchart() %>% 
  hc_chart(animation = FALSE) %>% 
  hc_title(text = "draggable points demo") %>% 
  hc_xAxis(categories = month.abb) %>% 
  hc_plotOptions(
    series = list(

    stickyTracking = FALSE
        ),
    column = list(
      stacking = "normal"
    ),
    line = list(
      cursor = "ns-resize"
    )
    ) %>% 

  hc_add_series(
    data = citytemp$berlin,
    draggableY = TRUE
  )

})

 }

ui.r

library("shiny")
library("shinydashboard")
library("highcharter")
library("dplyr")
library("viridisLite")
library("markdown")
library("quantmod")
library("tidyr")
library("ggplot2")
library("treemap")
library("forecast")
library("DT")
rm(list = ls())

dashboardPage(
  skin = "black",
  dashboardHeader(title = "highcharter", disable = FALSE),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Examples", tabName = "examples", icon = icon("bar-chart"))
    )
    #,
    #div(includeMarkdown("hcterinfo.md"), style = "padding:10px")
  ),
  dashboardBody(
    # tags$head(tags$script(src = "js/ga.js")),
    # tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "css/custom_fixs.css")),
    tabItems(
      tabItem(tabName = "examples",
              fluidRow(

              box(width = 6, highchartOutput("highchart")),
              box(width = 6, dataTableOutput("table"))

      )
    )
  )
))
jbkunst commented 8 years ago

Hi Tim (@tbenschop),

This was asked in #28 ;)! and here https://github.com/jbkunst/highcharter/issues/28#issuecomment-178047294 you can see a implementation https://jbkunst.shinyapps.io/highcharter/.

You need to create a drop event and push to server unsing js function Shiny.onInputChange.

Next time please make a minimal reproducible example. It's easy to focus in the functionality :smile:.

Regards,

tbenschop commented 8 years ago

Hi @jbkunst,

Thanks a lot. I'm used to give the full code as that is how you should do it at StackOverflow but I understand that this is not desired on github. Thanks :]

jbkunst commented 8 years ago

I think this not desire in stackoverflow too XD. How to create a Minimal, Complete, and Verifiable example (http://stackoverflow.com/help/mcve)

;)!