如何从 even_data 信息中检索用于绘图的原始数据?
library(plotly)
library(shiny)
ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("click")
)
server <- function(input, output, session) {
output$plot <- renderPlotly({
key <- row.names(mtcars)
p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
})
output$click <- renderPrint({
d <- event_data("plotly_click")
if (is.null(d)) "Click events appear here (double-click to clear)" else d
})
}
shinyApp(ui, server)
单击某个点时,示例输出类似于
curveNumber pointNumber x y key
1 1 3 24.4 3.19 Merc 240D
有没有办法将这些信息映射到原始数据集mtcars
?curveNumber
中的信息pointNumber
将如何有用?这些字段的含义是什么?