R 我能得到像“我能”这样的信息吗;“悬停位置”&引用;刷位置“;或;单击“位置”;
我想建立一个互动的图形,有光泽和生动。 Shiny有一个内置功能来获取有关用户交互的信息。例如:输入$plot\u单击、输入$plot\u dblclick、输入$plot\u悬停和输入$plot\u笔刷。 见: 有没有通过Plotly API实现这一点的选项?或者API只能处理一个方向 普洛特利真的很酷。我很想在我闪亮的应用程序中使用它 谢谢并致以最良好的问候R 我能得到像“我能”这样的信息吗;“悬停位置”&引用;刷位置“;或;单击“位置”;,r,shiny,plotly,R,Shiny,Plotly,我想建立一个互动的图形,有光泽和生动。 Shiny有一个内置功能来获取有关用户交互的信息。例如:输入$plot\u单击、输入$plot\u dblclick、输入$plot\u悬停和输入$plot\u笔刷。 见: 有没有通过Plotly API实现这一点的选项?或者API只能处理一个方向 普洛特利真的很酷。我很想在我闪亮的应用程序中使用它 谢谢并致以最良好的问候 Nico是的,通过postMessage API可以对Plotly图形进行单击和悬停绑定: 下面是如何将postMessage A
Nico是的,通过postMessage API可以对Plotly图形进行单击和悬停绑定: 下面是如何将postMessage API与Shining一起使用的示意图: 代码如下:
现在有一个
事件数据
函数,它来自plotly
包本身,可以处理悬停、点击、刷牙等操作
软件包中有一个闪亮的演示,介绍了使用方法:
library(plotly)
shiny::runApp(system.file("examples", "plotlyEvents", package = "plotly"))
app.R
library(shiny)
library(plotly)
ui <- fluidPage(
radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),
plotlyOutput("plot"),
verbatimTextOutput("hover"),
verbatimTextOutput("click"),
verbatimTextOutput("brush"),
verbatimTextOutput("zoom")
)
server <- function(input, output, session) {
output$plot <- renderPlotly({
# use the key aesthetic/argument to help uniquely identify selected observations
key <- row.names(mtcars)
if (identical(input$plotType, "ggplotly")) {
p <- ggplot(mtcars, aes(x = mpg, y = wt, colour = factor(vs), key = key)) +
geom_point()
ggplotly(p) %>% layout(dragmode = "select")
} else {
plot_ly(mtcars, x = mpg, y = wt, key = key, mode = "markers") %>%
layout(dragmode = "select")
}
})
output$hover <- renderPrint({
d <- event_data("plotly_hover")
if (is.null(d)) "Hover events appear here (unhover to clear)" else d
})
output$click <- renderPrint({
d <- event_data("plotly_click")
if (is.null(d)) "Click events appear here (double-click to clear)" else d
})
output$brush <- renderPrint({
d <- event_data("plotly_selected")
if (is.null(d)) "Click and drag events (i.e., select/lasso) appear here (double-click to clear)" else d
})
output$zoom <- renderPrint({
d <- event_data("plotly_relayout")
if (is.null(d)) "Relayout (i.e., zoom) events appear here" else d
})
}
shinyApp(ui, server, options = list(display.mode = "showcase"))
库(闪亮)
图书馆(绘本)
好的,给我点时间通读一遍。我把问题标为已回答的有点快。谢谢并致以最良好的祝愿,尼科克,我无法用最后两个链接中的一个解决问题。但第一个链接类似于:“任务:侦听-为单个事件或事件组(缩放、悬停或单击)指定回调”-但我不知道如何在R中正确使用它。我想我需要在JS中重新编码一些部分来完成它。我说得对吗?感谢并向NicoHi致以最良好的问候,您知道怎么做吗?如果有多个plotly图表,请使用source
调用单个plot。看见