0
如何從even_data信息中檢索用於繪圖的原始數據?將事件數據信息映射到Shiny reactive plot中的繪圖信息
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
中的信息將如何有用,這些字段意味着什麼?
謝謝!但是,我的問題主要集中在通過使用'curveNumber','pointNumber'來獲取它。 – Prradep
答案在編輯中。 –
此外,請務必明確地問你想要什麼,這是你的問題是:「有沒有辦法將這些信息映射到原始數據集mtcars」,第一次提交已經滿足(我使用了密鑰)。第二次用curveNumber和pointNumber提交。 –