I am developing a Shiny application that contains a scatter plotly . I would like the user to be able to click on the graph to record the event using the event_data function, but then be able to clear this event by pressing the actionButton button. The following is an example code example:
library(shiny) library(plotly) ui <- fluidPage( actionButton("clearEvent", label = "clear event"), verbatimTextOutput("plotVal"), plotlyOutput('plot1') ) server <- function(input, output, session) { output$plot1 <- renderPlotly({ d <- diamonds[sample(nrow(diamonds), 1000), ] plot_ly(d, x = ~carat, y = ~price, color = ~carat, size = ~carat, text = ~paste("Clarity: ", clarity)) }) output$plotVal <- renderPrint({ e <- event_data("plotly_click") if (is.null(e)) { NULL } else { e } }) observeEvent(input[["clearEvent"]], { e <- NULL }) } shinyApp(ui = ui, server = server)
This does not clear the event as I expected. A look at the code for event_data shows that this is probably because it is stored inside the session object itself. Any ideas how I can overwrite it?
The only similar thing I came across is a Bright click on an event , but it is very hacky and doesn't seem to work for me.
source share