shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Request: plotOutput: a way to differentiate between click and brush

Open daattali opened this issue 9 years ago • 6 comments

Originally posted in shiny google group

If I want to have a plot in my shiny app that the user can click on or choose certain regions, I'll use the click and brush arguments of plotOutput. However, when a brush is initiated, the click handler is also called. In some cases it can be useful to know when a click is made and when a brush is made, but if a click is part of a brush then I want to ignore it.

Example: in the following app, if you just brush (click some k somewhere and drag the mouse), you get a "click" message as well as a "brush" message. I want to only get the "brush" message in that case.

library(shiny)
library(ggplot2)
runApp(shinyApp(
  ui = fluidPage(
    plotOutput("plot", click = "click", brush = "brush")
  ),
  server = function(input, output, session) {
    output$plot <- renderPlot({
      ggplot(mtcars, aes(wt, mpg)) + geom_point()
    })
    observeEvent(input$click, {
      cat("clicked\n")
    })
    observeEvent(input$brush, {
      cat("brushed\n")
    })
  }
))

I noticed that the click event is triggered on mousedown. If you agree with my proposed behaviour of not triggering a click when a brush is made, maybe a potential solution would be to change the trigger to be on mouseup, and when it happens check if a brush was made.

daattali avatar Sep 07 '15 19:09 daattali

This sounds like a good idea. There is some existing code that uses timing to distinguish between clicks and double-clicks, and something similar could be used for this as well.

wch avatar Sep 08 '15 15:09 wch

Hi @wch , I just asked you in the Shiny devcon if this is still an issue. I just tried it, and a regular click does indeed still get registered the moment I mousedown on the plot. Shiny v0.13.0

daattali avatar Jan 30 '16 21:01 daattali

Voting for this one. This is a nuisance. Thanks

TomasHovorka avatar May 13 '16 13:05 TomasHovorka

+1

tvedebrink avatar Nov 23 '16 09:11 tvedebrink

Still a thing; reproduced with Shiny 1.3.2.

alandipert avatar Apr 26 '19 23:04 alandipert

Is this the only known way to deal with the issue?

nick-youngblut avatar Mar 12 '24 03:03 nick-youngblut