Shiny Plotly event_data只有闪亮的服务器才会出错

我正在使用闪亮,情节和闪亮的BS,如下所示,当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)
点赞