Shiny Plotly event_data 仅在闪亮的服务器上出错
Shiny Plotly event_data Error only with shiny server
我正在使用 shiny、plotly 和 shinyBS,如下所示,当情节上发生 plotly_click 事件时,生成带有新情节的模态弹出窗口。当我 运行 在本地以及在本地浏览器中时,它都能完美地找到。
然而,当我将它部署到 Shiny 服务器上时,我得到了这个错误,并且不知道它是什么意思。有什么想法吗?
library(shiny)
library(plotly)
library(shinyBS)
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')),
bsModal('boxPopUp', '', '', plotlyOutput('box'))
)
server <- function(input, output, session) {
output$scatter <- renderPlotly({
plot_ly(df1, x = ~x, y = ~y, mode = 'markers',
type = 'scatter', source = 'scatter')
})
observeEvent(event_data("plotly_click", source = "scatter"), {
toggleModal(session, "boxPopUp", toggle = "toggle")
})
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服务器日志中):
Warning: Error in event_data: attempt to apply non-function
Stack trace (innermost first):
59: event_data
58: observeEventExpr
1: runApp
这是使用 Shiny 0.14 中提供的模态对话框的修改版本。
在 RStudio、本地浏览器、shinyapps 和我本地安装的闪亮服务器开源版本上进行了测试。
这是代码:
library(shiny)
library(plotly)
library(shinyBS)
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'))
)
server <- function(input, output, session) {
output$scatter <- renderPlotly({
plot_ly(df1, x = x, y = y, mode = 'markers',
type = 'scatter', source = 'scatter')
})
observeEvent(event_data("plotly_click", source = "scatter"), {
showModal(modalDialog(
renderPlotly({
plot_ly(df2, x = x, y = y, type = 'box')
}),
easyClose = TRUE
))
})
}
shinyApp(ui = ui, server = server)
我正在使用 shiny、plotly 和 shinyBS,如下所示,当情节上发生 plotly_click 事件时,生成带有新情节的模态弹出窗口。当我 运行 在本地以及在本地浏览器中时,它都能完美地找到。
然而,当我将它部署到 Shiny 服务器上时,我得到了这个错误,并且不知道它是什么意思。有什么想法吗?
library(shiny)
library(plotly)
library(shinyBS)
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')),
bsModal('boxPopUp', '', '', plotlyOutput('box'))
)
server <- function(input, output, session) {
output$scatter <- renderPlotly({
plot_ly(df1, x = ~x, y = ~y, mode = 'markers',
type = 'scatter', source = 'scatter')
})
observeEvent(event_data("plotly_click", source = "scatter"), {
toggleModal(session, "boxPopUp", toggle = "toggle")
})
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服务器日志中):
Warning: Error in event_data: attempt to apply non-function
Stack trace (innermost first):
59: event_data
58: observeEventExpr
1: runApp
这是使用 Shiny 0.14 中提供的模态对话框的修改版本。 在 RStudio、本地浏览器、shinyapps 和我本地安装的闪亮服务器开源版本上进行了测试。
这是代码:
library(shiny)
library(plotly)
library(shinyBS)
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'))
)
server <- function(input, output, session) {
output$scatter <- renderPlotly({
plot_ly(df1, x = x, y = y, mode = 'markers',
type = 'scatter', source = 'scatter')
})
observeEvent(event_data("plotly_click", source = "scatter"), {
showModal(modalDialog(
renderPlotly({
plot_ly(df2, x = x, y = y, type = 'box')
}),
easyClose = TRUE
))
})
}
shinyApp(ui = ui, server = server)