Returns the data of the most recent plotly event of a given type, from
the plot with the given source (see event_source()); NULL before any
such event. Must be called in a reactive context of a Shiny app.
Usage
event_data(
event = c("plotly_hover", "plotly_unhover", "plotly_click", "plotly_doubleclick",
"plotly_selected", "plotly_selecting", "plotly_brushed", "plotly_brushing",
"plotly_deselect", "plotly_relayout", "plotly_restyle", "plotly_legendclick",
"plotly_legenddoubleclick", "plotly_clickannotation", "plotly_afterplot",
"plotly_sunburstclick"),
source = "A",
session = shiny::getDefaultReactiveDomain(),
priority = c("input", "event")
)Details
Point events (click, hover, selected, ...) return a data frame with
curveNumber, pointNumber, x, y and, where available, z,
customdata and key. plotly_relayout returns the changed layout
properties (e.g. axis ranges after zooming).
Examples
if (interactive() && requireNamespace("shiny", quietly = TRUE)) {
ui <- shiny::fluidPage(plotlyOutput("plot"), shiny::verbatimTextOutput("click"))
server <- function(input, output, session) {
output$plot <- renderPlotly(px_data_iris() |> px_scatter(x = ~sepal_width, y = ~sepal_length))
output$click <- shiny::renderPrint(event_data("plotly_click"))
}
shiny::shinyApp(ui, server)
}