Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only last unselect event observed by shiny #786

Open
j-kreis opened this issue Nov 27, 2022 · 1 comment
Open

Only last unselect event observed by shiny #786

j-kreis opened this issue Nov 27, 2022 · 1 comment

Comments

@j-kreis
Copy link

j-kreis commented Nov 27, 2022

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)

Copy link

stale bot commented Mar 17, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant