googlevis $ 运算符对原子向量无效
googlevis $ operator is invalid for atomic vectors
我遇到了可怕的“$ operator is invalid for atomic vectors”错误。当我添加 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)
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)
我通过谷歌搜索 "shiny gvisLineChart" 找到了更多示例 here。使用 googleVis_0.6.1
、shiny_0.13.2
、R 3.2.5
进行测试
我遇到了可怕的“$ operator is invalid for atomic vectors”错误。当我添加 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)
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)
我通过谷歌搜索 "shiny gvisLineChart" 找到了更多示例 here。使用 googleVis_0.6.1
、shiny_0.13.2
、R 3.2.5