I am maintaining my code for a big and bulky shiny dashboard, and I noticed that the click-event functionality doesn't reset anymore.
After stripping it down to a minimal working example, and comparing to solutions from https://stackoverflow.com/a/44543204/11703379 and https://community.plot.ly/t/reseting-click-events/2718, I come to conclusion that there must have been a change in either plotly
, or shinyjs
libraries, which disable this feature.
By halting the execution at the plot, I see that the plot object does carry the source attribute correctly.
library(plotly)
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
plotlyOutput("plot"),
extendShinyjs(text = "shinyjs.resetClick = function() { Shiny.onInputChange('.clientValue-plotly_click-plot', 'null'); }"),
actionButton("reset", "Reset click"),
verbatimTextOutput("click")
)
server <- function(input, output, session) {
observeEvent(input$reset, js$resetClick())
output$click <- renderPrint(event_data("plotly_click", source = "plot" ))
output$plot <- renderPlotly(
plot_ly(mtcars, x = ~mpg, y = ~wt,
type="scatter",
mode="markers",
source = "plot") %>%
event_register("plotly_click")
)
output$click <- renderPrint({
d <- event_data(source = "plot","plotly_click")
if (is.null(d)) "No click" else d
})
}
shinyApp(ui, server)
Can anyone confirm this?
I am using plotly
version 4.9.0,
and shinyjs
version 1.0.