highcharter
highcharter copied to clipboard
Only last unselect event observed by shiny
I want to implement an interaction between a DT::datatable and a highcharter scatter plot (point and row selection). When selecting multiple (2+) points in the plot (using Strg + click) and then selecting another point (without Strg + click) all points in the plot except for the last clicked are deselected and the unselect event is triggered on the javascript side. However, the shiny input that I set in the unselect event is only triggered for the last point.
Is there a possibility to change this behaviour? If not, is it possible to have multi selection without the Strg key event?
library(shiny)
library(highcharter)
library(tibble)
dt <- tibble::tibble(x = rnorm(20), y = rnorm(20),
id = 1:20)
ui <- fluidPage(
shiny::fluidRow(
highcharter::highchartOutput("foo")
)
)
server <- function(input, output, session) {
output$foo = highcharter::renderHighchart({
unselectFunction <- JS("function(event) {
# triggers for each programmatic unselect
console.log('unselect: ' + this.id.toString())
Shiny.onInputChange('unselect', this.id);
}")
highcharter::highchart() %>%
hc_add_series(data = dt,
type = "scatter",
mapping = highcharter::hcaes(x = x, y = y)) %>%
highcharter::hc_plotOptions(
scatter = list(allowPointSelect = TRUE,
point = list(events = list(unselect = unselectFunction))))
})
shiny::observeEvent(input$unselect, {
# only triggered once (the last programmatic unselect)
})
}
shinyApp(ui, server)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. Feel free to reopen it if you find it necessary.