Reputation: 1
I'm trying to click on a category in a pie chart built with highcharts and use the category to filter data in a line chart in R shiny app.
Upvotes: 0
Views: 899
Reputation: 255
Following the previous answer from @porkChop you can also add below code to your hc_plotOptions in order to get a selection visualization.
hc_plotOptions(
series = list(
stacking = FALSE, allowPointSelect = TRUE ,events = list(click = click_js))
)
Upvotes: 0
Reputation: 29397
You can capture the click using the hc_plotOptions
settings, like so:
library(shiny)
library(highcharter)
ui <- fluidPage(
column(3,
highchartOutput("hcontainer",height = "300px")
),
column(3,
textOutput("clicked")
)
)
server <- function(input, output){
click_js <- JS("function(event) {Shiny.onInputChange('pieclick',event.point.name);}")
output$hcontainer <- renderHighchart({
highchart() %>%
hc_chart(type = "pie") %>%
hc_add_series(data = list(
list(y = 3, name = "cat 1"),
list(y = 4, name = "dog 11"),
list(y = 6, name = "cow 55"))) %>%
hc_plotOptions(series = list(events = list(click = click_js)))
})
output$clicked <- renderText({
input$pieclick
})
}
shinyApp(ui, server)
Upvotes: 4