[英]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.