我想使用点击事件中的数据获取nearPoints
。在renderPlotly单击事件中使用nearPoints时出现闪烁错误
我发现了Shiny webpage下面的代码片段,它可以正常工作。
output$plot <- renderPlot({
d <- data()
plot(d$speed, d$dist)
})
output$plot_clickedpoints <- renderPrint({
# For base graphics, we need to specify columns, though for ggplot2,
# it's usually not necessary.
res <- nearPoints(data(), input$plot_click, "speed", "dist")
if (nrow(res) == 0)
return()
res
})
我试图模仿的做法上面的识别使用点击事件数据的Plotly地块nearPoints
。但是,它没有工作。
output$plot <- renderPlotly({
d <- data()
plot(d$speed, d$dist)
})
output$plot_clickedpoints <- renderPrint({
# For base graphics, we need to specify columns, though for ggplot2,
# it's usually not necessary.
res <- nearPoints(data(), event_data("plotly_click"), "speed", "dist")
if (nrow(res) == 0)
return()
res
})
关于如何将坐标信息传递给情节图的任何想法?
优秀的建议@弗洛里安。当我选择图上可用的点时,它运作良好。然而,当我点击plot'cyl = 5'或'cyl = 7'上的某个地方时,它不会以相同的方式工作。 – Prradep
@Prradep,恐怕解决这个问题超出了我的能力,因为我对JavaScript的知识有限。我首先想到使用plotly_hover解决方案,并使用shinyjs的onclick()单击时获取坐标,但是plotly_hover与plotly_click具有相同的问题。我怀疑甚至有可能从图中的一个随机点获取坐标,参见[这里](https://community.plot.ly/t/how-can-i-get-exact-xy-pixel-coordinates -of-A-标记点/ 3009)。但是,从我的角度来看,这有更多的猜测,还有其他人可以更好地解决这个问题(如卡森)。 – Florian
我同意你的意见。我在阅读这里提到的帖子后发布了这个问题。我会尝试推测的方法。 – Prradep