1
Plotly具有函數event_data,它將響應點擊圖表上的點擊。但是,您必須爲event_data指定一個「源」,以標識要觀看的情節。R - Plotly:獲取單擊圖形的ID
有沒有方法可以響應點擊任何情節並獲得給定點擊的來源ID?
Plotly具有函數event_data,它將響應點擊圖表上的點擊。但是,您必須爲event_data指定一個「源」,以標識要觀看的情節。R - Plotly:獲取單擊圖形的ID
有沒有方法可以響應點擊任何情節並獲得給定點擊的來源ID?
可以遍歷源列表,但你必須保持軌道的改變自己作爲唯一一個給定用地新的點擊覆蓋了以前的單擊事件:
shinyApp(ui=fluidPage(plotlyOutput("plot1"),
plotlyOutput("plot2")),
server=
function(input, output, session) {
output$plot1 <- renderPlotly(plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, source="plot1"))
output$plot2 <- renderPlotly(plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, source="plot2"))
states <- reactiveValues(source = c("plot1", "plot2"), value = c(0,0), changed = c(FALSE,FALSE))
observe({
for(src in states$source){
if(!is.null(event_data("plotly_click", source = src))){
value <- event_data("plotly_click", source = src)[[2]]
if(states$value[states$source==src]!=value){
states$value[states$source==src] <- value
states$changed[states$source==src] <- TRUE
}
}
}
if(sum(states$changed)>0)
print(paste(states$source[states$changed], 'has changed'))
states$changed <- c(FALSE,FALSE)
})
})
感謝您的幫助! –