googlevis $运算符对原子向量无效

时间:2016-09-16 15:27:58

标签: r googlevis

我击中了可怕的" $运算符对原子向量无效"错误。当我添加gvisLineChart时会发生这种情况。有什么建议吗?

library(shiny)
library(googleVis)

#this is a dput of a sql query to make the example reproducible. 
#In reality this will be an RODBC sqlQuery result
dataset <- structure(list(id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 
  value = c(1.68294196961579, 82.4641565111739, 83.3056274959818, 
  6.73176787846317, 5.89029689365528, 2.52441295442369, 4.20735492403948, 
  0.841470984807897, 5.04882590884738, 15.1464777265421)), 
  .Names = c("id", "value"), row.names = c(NA, 10L), class = "data.frame")

ui <- shinyUI(
     plotOutput("motionPlot")
)

server <- shinyServer(function(input, output) {

    output[["motionPlot"]] <- renderGvis({

    Line <- gvisLineChart(dataset, xvar=c("id"), yvar=c("value"))     
    plot(Line)
   })

})

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

googleVis图不像R中的常规图。常规图产生静态图像,但googleVis基本上生成带有HTML和javascript数据的迷你网页。因此,您不应使用plotOutput,应使用htmlOutput将其呈现给页面。此外,您也不需要使用plot()。这将适用于您的示例数据

ui <- shinyUI(
     htmlOutput("motionPlot")
)

server <- shinyServer(function(input, output) {
    output[["motionPlot"]] <- renderGvis({
        gvisLineChart(dataset, xvar=c("id"), yvar=c("value"))     
   })
})

shinyApp(ui = ui, server = server)

我通过谷歌搜索“闪亮的gvisLineChart”找到了更多的例子here。使用googleVis_0.6.1shiny_0.13.2R 3.2.5

进行了测试