[英]Click event in highcharter treemap (R shiny)
基于这个问题的答案: Highcharter - Clickable Pie Chart - How to get the category name from the slice clicked on a Pie Chart in Shiny? ,我正在尝试在 R Shiny 应用程序中的 highcharter treemap 上捕获点击事件的 output。
我想我只需要正确的名称来替换这个 javascript function 中的“event.point.name”:
function(event) {Shiny.onInputChange('treemapclick', event.point.name);}
但我不确定在哪里看。
提前感谢您的慷慨!
library(shiny)
library(highcharter)
library(gapminder)
ui <- fluidPage(
column(12, highchartOutput("hcontainer",height = "300px")),
column(12, textOutput("clicked")))
server <- function(input, output){
click_js <- JS("function(event) {Shiny.onInputChange('treemapclick', event.point.name);}")
output$hcontainer <- renderHighchart({
gapminder::gapminder %>%
filter(year == 2007) %>%
highcharter::data_to_hierarchical(group_vars = c(continent, country), size_var = pop) %>%
hchart(type = "treemap") %>%
hc_plotOptions(events = list(click = click_js))
})
output$clicked <- renderText({
input$treemapclick
})
}
shinyApp(ui, server)
想通了这个问题。 问题不在于 event.point,name 变量。 但使用 plot 选项:将其更改为:
hc_plotOptions(treemap = list(events = list(click = click_js)))
做的伎俩。
工作代表:
library(shiny)
library(highcharter)
library(gapminder)
ui <- fluidPage(
column(12, highchartOutput("hcontainer",height = "300px")),
column(12, textOutput("clicked")))
server <- function(input, output){
click_js <- JS("function(event) {Shiny.onInputChange('treemapclick', event.point.name);}")
output$hcontainer <- renderHighchart({
gapminder::gapminder %>%
filter(year == 2007) %>%
highcharter::data_to_hierarchical(group_vars = c(continent, country), size_var = pop) %>%
hchart(type = "treemap") %>%
hc_plotOptions(treemap = list(events = list(click = click_js)))
})
output$clicked <- renderText({input$treemapclick })
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.