_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.
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.
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
Voting for this one. This is a nuisance. Thanks
+1
Still a thing; reproduced with Shiny 1.3.2.
Most helpful comment
Voting for this one. This is a nuisance. Thanks