【问题标题】:Unable to deploy the googleVis motion chart using R shiny server无法使用 R 闪亮服务器部署 googleVis 动态图表
【发布时间】:2015-10-07 08:43:11
【问题描述】:

动态图表在我自己的计算机上显示得很好,虽然图表显示在另一个 IE 窗口而不是 RStudio 的内部窗口上。 但是,当我使用 R Shiny 服务器在 Web 上部署 googleVis 动态图表时,此错误消息显示:

  Error: $ operator is invalid for atomic vectors

我还使用以下命令检查了它们,结果表明它们不是原子的:

  >is.recursive(Fruits)
  [1] TRUE
  >is.atomic(Fruits)
  [1] FALSE

可复现的代码如下,我已经简化并使用内部数据“水果”来演示它;问题依然存在,IE9 的动态图表没有显示在同一个窗口中,而是出现在另一个窗口中。 而当使用shiny-server部署时,情况变得更糟,运动图表根本没有出现并显示相同的错误消息

服务器。 R

  library(googleVis)
  library(shiny)
  shinyServer(function(input, output) {
    output$motionchart2 <- renderGvis({
     M1 <- gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
     plot(M1)
   })
  })

UI.R

  library(shiny)
  library(googleVis)
  shinyUI(fluidPage(
  titlePanel("Analysis"),
  mainPanel(
   navlistPanel(
    tabPanel("MotionChart",h1("Motion Chart"),tableOutput("motionchart2"))
  )
 )
 ) 
 )

【问题讨论】:

  • 你能发布整个代码,或者至少足以制作一个reproducible example 吗?
  • @tospig:我在下面添加了可重现的代码,感谢您的建议。
  • 我相信 renderGvis 需要输出为 HTML,因此在您的 UI 中,将 tableOutput 替换为 htmlOutput("motionchart2")。你也可以尝试用 return(M1) 替换 plot(M1) 吗?
  • @BogdanRau:对不起,我也尝试使用“return”和“htmloutput”,但仍然无效,谢谢。

标签: r shiny googlevis


【解决方案1】:

在 renderGivs 部分渲染图表时不需要 plot 函数。我稍微修改了您的代码的服务器部分。当您运行应用程序时,您必须在浏览器中打开它,否则图表将不会显示。

library(shiny)
library(googleVis)

ui = shinyUI(fluidPage(
    titlePanel("Analysis"),
    mainPanel(
        navlistPanel(
            tabPanel("MotionChart",h1("Motion Chart"),tableOutput("motionchart2"))
        )
    )
))

server = shinyServer(function(input, output) {
    output$motionchart2 <- renderGvis({
        gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")
    })
})

runApp(list(ui = ui, server = server))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 2018-12-04
    • 2016-12-28
    • 2016-08-01
    • 2013-12-21
    • 1970-01-01
    • 2018-05-31
    相关资源
    最近更新 更多