0
我使用闪亮来创建一个简单的应用程序。类型'closure'的对象不可子集[GGplot2,Shiny]
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Power Breakdown!"),
sidebarLayout(
sidebarPanel()
mainPanel(
plotOutput("plt"))
)
))
和server.R是(需要的数据集是在loc)
library(shiny)
library(ggplot2)
df <- readRDS("dataframe-path")
shinyServer(
function(input, output) {
output$plt <- renderPlot({
df$timestamp <- as.Date(df$timestamp)
p <- ggplot(df,aes(df$timestamp,df$power))+theme_bw() +geom_point()
print(p)
})
})
当运行该应用程序,则产生以下错误
Error in df$timestamp : object of type 'closure' is not subsettable
每当我运行相同的服务器脚本作为正常的R脚本,一切正常,但同时使用相同的代码片段闪亮的结果在上述错误。
然后尝试更改“'p < - ggplot(df,aes(df $ timestamp,df $ power))+ theme_bw()+ geom_point()'到'p < - ggp lot(df,aes(timestamp,power))+ theme_bw()+ geom_point()' – jeremycg
谢谢,它工作。我不知道为什么相同的代码在独立的R脚本中工作的原因,但闪亮失败。真的,疯了。请把你的评论作为答案。 –
它与'ggplot' [范围本身在函数内部]的方式有关(https://stackoverflow.com/questions/22287498/scoping-of-variables-in-aes-inside-a-function-in-ggplot) – jeremycg