Skip to content

Bug: double clicking on the plot to clear the selection triggers the "plotly_selected" event twice #1122

Closed
@daattali

Description

@daattali

This only seems to happen when there are no single points currently selected with a click.

Code:

library(shiny)
library(plotly)

ui <- fluidPage(
  plotlyOutput("plot"),
  verbatimTextOutput("click"),
  verbatimTextOutput("brush")
)

server <- function(input, output, session) {
  
  nms <- row.names(mtcars)
  
  output$plot <- renderPlotly({
    p <- ggplot(mtcars, aes(x = mpg, y = wt, key = nms)) + geom_point()
    ggplotly(p) %>% layout(dragmode = "lasso")
  })
  
  output$click <- renderPrint({
    message('clicked')
    d <- event_data("plotly_click")
    if (!is.null(d)) d
  })
  
  output$brush <- renderPrint({
    message('selected')
    d <- event_data("plotly_selected")
    if (!is.null(d)) d
  })
  
}

shinyApp(ui, server)

If there isn't a selected single point via a click, then double clicking anywhere will trigger "selected" twice. If there is a single point selected, then it will only trigger once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions