Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically Click TreeMap Point #47

Open
jdonnell01 opened this issue Jan 14, 2019 · 0 comments
Open

Dynamically Click TreeMap Point #47

jdonnell01 opened this issue Jan 14, 2019 · 0 comments

Comments

@jdonnell01
Copy link

I am using R, Shiny, and Highcharter and I would like to click an Action Button and have the treemap drill down into a section that I designate. So for instance I click the "mybutton" action button and it drills down into the Europe section. I have tried three separate functions (jscode1, jscode2, jscode3), all of which do not work. is this possible with the current API? Reproducible code:

library("shiny")
library("highcharter")
library("shinyjs")
library("treemap")
library("viridisLite")
data(GNI2014)

jscode <- "shinyjs.drillDownFunction = function() {
  var chart = $('#hcontainer').highcharts();
  chart.series[0].data[0].firePointEvent('click');
  console.log(chart);}"

jscode2 <- "shinyjs.drillDownFunction2 = function() {
  var chart = $('#hcontainer').highcharts();
  chart.series[0].data[0].series.hcEvents.click[0]();
  console.log(chart);}"

jscode3 <- "shinyjs.drillDownFunction3 = function() {
  var chart = $('#hcontainer').highcharts();
  Highcharts.fireEvent(chart.series[0].data[0], 'click');
  console.log(chart);}"

ui <-
  fluidPage(
    useShinyjs(),
    extendShinyjs(text = jscode, functions = "drillDownFunction"),
    extendShinyjs(text = jscode2, functions = "drillDownFunction2"),
    extendShinyjs(text = jscode3, functions = "drillDownFunction3"),
    fluidRow(
      column(width = 8, highchartOutput("hcontainer"))),
    fluidRow(
      column(width = 4, textOutput("text"))),
    fluidRow(
      column(width = 4, actionButton("mybutton", "Drill Down into TreeMap"),
                        actionButton("mybutton2", "Drill Down into TreeMap"),
                        actionButton("mybutton3", "Drill Down into TreeMap")))
    )

server <- function(input, output) {      
  
  tm <- treemap(GNI2014, index = c("continent", "iso3"),
                vSize = "GNI", vColor = "population",
                type = "value", palette = magma(12))
  
  output$hcontainer <- renderHighchart({      
    
    hctreemap(tm, allowDrillToNode = TRUE, allowPointSelect = TRUE) %>% 
      hc_title(text = "Gross National Income World Data")
  })
  
  shinyjs::onclick("mybutton", {
    js$drillDownFunction()
  })
  
  shinyjs::onclick("mybutton2", {
    js$drillDownFunction2()
  })
  
  shinyjs::onclick("mybutton3", {
    js$drillDownFunction3()
  })
  
}

shinyApp(ui = ui, server = server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant