treemap
treemap copied to clipboard
Dynamically Click TreeMap Point
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)