我可以取回如下信息:"hover location"、"Brush location" 或 "click location"
Can I get back info like: "hover location", "Brush location" or "click location"
我想建立一个有光泽和情节的交互式图表。
Shiny 有一个内置功能来获取有关用户交互的信息。喜欢:input$plot_click、input$plot_dblclick、input$plot_hover 和 输入$plot_brush。
看:
http://shiny.rstudio.com/articles/plot-interaction.html
是否有任何选项可以通过 Plotly API 获取此内容?或者 API 可以只处理一个方向吗?
Plotly 真的很酷。很想在我闪亮的应用程序中使用它。
谢谢并致以最诚挚的问候
妮可
是的,通过 postMessage API 可以点击和悬停绑定到 Plotly 图:
https://github.com/plotly/postMessage-API
关于如何使用 postMessage API 和 Shiny 的草图在这里:
http://moderndata.plot.ly/dashboards-in-r-with-shiny-plotly/
plotly
包本身现在有一个 event_data
函数可以处理悬停、点击、刷牙等操作。
包中有Shiny demo,介绍了用法:
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"))
他们的GitHub主页面也有刷链接和点击的例子:
我想建立一个有光泽和情节的交互式图表。 Shiny 有一个内置功能来获取有关用户交互的信息。喜欢:input$plot_click、input$plot_dblclick、input$plot_hover 和 输入$plot_brush。 看: http://shiny.rstudio.com/articles/plot-interaction.html
是否有任何选项可以通过 Plotly API 获取此内容?或者 API 可以只处理一个方向吗?
Plotly 真的很酷。很想在我闪亮的应用程序中使用它。
谢谢并致以最诚挚的问候
妮可
是的,通过 postMessage API 可以点击和悬停绑定到 Plotly 图: https://github.com/plotly/postMessage-API
关于如何使用 postMessage API 和 Shiny 的草图在这里: http://moderndata.plot.ly/dashboards-in-r-with-shiny-plotly/
plotly
包本身现在有一个 event_data
函数可以处理悬停、点击、刷牙等操作。
包中有Shiny demo,介绍了用法:
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"))
他们的GitHub主页面也有刷链接和点击的例子: