【问题标题】:Plotly variable not found after deploying to shiny server部署到闪亮服务器后找不到 Plotly 变量
【发布时间】:2018-08-10 10:28:07
【问题描述】:

我创建了一个 Shiny 应用程序,其中包含一些 Plotly 对象。在 RStudio 中预览时一切正常。但是,当我将应用程序部署到 Shiny 服务器(本地)并打开应用程序时,未显示绘图。在浏览器(Chrome 或 Safari)中查看开发者控制台时,我看到以下错误 Can't find variable: Plotly,它指向 plotly.js 的第 141 行,在以下代码中为 var plot = Plotly.plot(graphDiv, x):

  //if no plot exists yet, create one with a particular configuration

  if (!instance.plotly) {

    var plot = Plotly.plot(graphDiv, x);
    instance.plotly = true;
    instance.autosize = x.layout.autosize || true;
    instance.width = x.layout.width;
    instance.height = x.layout.height;

我在 Chrome 和 Safari 中对此进行了测试,并且在两种浏览器中都发生了这种情况,但是当我在 Chrome 中刷新页面时,绘图有时会起作用。

所以为了进一步测试这一点,我从 Plotly 网站上获取了this code,并将其部署到我们的 Shiny 服务器环境中,看看是否会发生相同的行为,是这种情况。因此,我不认为我犯了编码错误。

我正在使用以下软件包版本:

  • 情节4.7.1
  • 闪亮的 1.0.5
  • htmlwidgets 1.0
  • 闪亮服务器 v1.5.3.838

有谁知道如何解决这个问题?我是否遗漏了一些软件包,或者是否需要在 Shiny 服务器中配置某些东西才能使其正常工作?

谢谢!

【问题讨论】:

  • 您的服务器上是否安装了 rstudio 服务器?您可以尝试在 rstudio 中运行您的代码,看看它是否可以帮助您检测到您遇到的问题。
  • 我们确实在同一台服务器上安装了该应用程序,我也从 rstudio 尝试了该应用程序。它工作正常并且绘图显示正确。将应用部署到闪亮服务器时会出现问题。
  • 我也有一个非常相似的问题。如果我在这里使用他们提供的示例,我也会收到 500 错误:plotly-r.com/linking-views-with-shiny.html

标签: r shiny plotly shiny-server


【解决方案1】:

我认为您可能需要的是 renderPlotly 而不是服务器中的 renderPlot。如果您这样做,该图将显示在查看器上,但不会出现在闪亮的弹出窗口(空白图表)中,并且在部署时将不起作用。将 renderPlot 替换为 renderPlotly 的一个例子是:

ui <- dashboardPage(skin = "blue",
                dashboardHeader(title= "Fig. 11: State Forecasting and Nowcasting", titleWidth = 450),
                dashboardSidebar(disable=TRUE),
                dashboardBody(
                  fillPage(padding = 0,
       box(title="", id="normal", solidHeader = TRUE, status = "primary", width=7,
                plotlyOutput("plot1", height = 250)), 
        box(title="State to Examine", background = "black", width=5, 
                selectInput("variable", "State:", choices= sort(unique(afteradd2$State)), selected="Ohio")),
       box(title="Forecast Length", background = "black", width=5, 
                selectInput("variable.two", "Forecast:", choices= c("Nowcast", "Three Month Forecast",
                                                             "Six Month Forecast"), selected="Nowcast"))
        )))
server <- function(input, output) {


output$plot1<- renderPlotly({
par(mfrow=c(1,1))
par(mar = c(4, 5, 4, 4)) 
fstate(input$variable, input$variable.two)})}


shinyApp(ui=ui, server=server)

如果没有看到您的代码,很难确定。如果这不是您的问题,您能否分享您的代码以便我提供帮助?

【讨论】:

    猜你喜欢
    • 2015-05-04
    • 2018-07-20
    • 1970-01-01
    • 2012-08-06
    • 2020-01-09
    • 2016-12-28
    • 2017-07-05
    • 1970-01-01
    • 2016-08-15
    相关资源
    最近更新 更多