【发布时间】:2016-08-22 05:02:17
【问题描述】:
这是我使用plotly_click 事件选择性地显示另一个情节的基本闪亮应用程序的代码。我希望该侧箱图在模式弹出窗口中呈现,而不是在页面内的一侧。
library(shiny)
library(plotly)
df1 <- data.frame(x = 1:10, y = 1:10)
df2 <- data.frame(x = c(rep('a', 10), rep('b', 10)),
y = c(rnorm(10), rnorm(10, 3, 1)))
ui <- fluidPage(
column(6, plotlyOutput('scatter')),
column(6, plotlyOutput('box'))
)
server <- function(input, output) {
output$scatter <- renderPlotly({
plot_ly(df1, x = x, y = y, mode = 'markers', source = 'scatter')
})
output$box <- renderPlotly({
eventdata <- event_data('plotly_click', source = 'scatter')
validate(need(!is.null(eventdata),
'Hover over the scatter plot to populate this boxplot'))
plot_ly(df2, x = x, y = y, type = 'box')
})
}
shinyApp(ui = ui, server = server)
我能够关注这个问题 (Shiny: plot results in popup window) 和响应,并尝试将其与 plotly_click 的 trigger 一起使用,但没有成功。知道如何通过巧妙的悬停点击事件来完成同样的事情吗?
更新:我可以清楚地看到plotly 绘图可以在shinyBS 模态弹出窗口中呈现,如此代码所示。
df1 <- data.frame(x = 1:10, y = 1:10)
ui <- fluidPage(
actionButton('go', 'Click Go'),
bsModal('plotlyPlot', 'Here is a Plot', 'go', plotlyOutput('scatter1'))
)
server <- function(input, output) {
output$scatter1 <- renderPlotly({
plot_ly(df2, x = x, y = y, mode = 'markers', source = 'scatter1')
})
}
shinyApp(ui = ui, server = server)
我希望plotly_click 或plotly_hover 作为触发器而不是actionButton(在原始示例中)。
【问题讨论】:
-
您对使用 JS 和 CSS 感到满意吗?