[英]object of type 'closure' is not subsettable: R shiny App
I am trying to create graph app using R shiny. 我正在尝试使用R闪亮创建图形应用程序。 So I take input from the user for route, stop/trip id, (boarding, alighting or load) from the user.
因此,我从用户那里获取用户的路线,停止/旅行ID,(登机,下车或加载)的输入。 So the ui.r is
所以ui.r是
ui <- fluidPage(
pageWithSidebar(
headerPanel('FAST_TRIPS Visulization', windowTitle = "Fast_trips Visaualization"),
sidebarPanel(
selectInput('route', 'Choose the Route No.', unique(y['route_id'])),
selectInput('id', 'Please Choose Stop or Trip ID', c('stop_id','trip_id')),
selectInput('rider', 'What do you wanna compare?', c('boarding', 'alighting', 'load')),
radioButtons('method','Please select your method', c('Sum', 'Average'))),
mainPanel(
plotOutput('plot1')
)
)
)
Then I am trying to extract the data for the specific route and aggregate values for example boarding with stop_id and trying to create a barplot for those stop_id. 然后我试图提取特定路线和聚合值的数据,例如使用stop_id登机,并尝试为那些stop_id创建一个条形图。 The server.R is below
server.R在下面
server <- function(input, output, session) {
# Combine the selected variables into a new data frame
selectedData <- reactive({
y[c('route_id', input$id, input$rider)]
})
data <- reactive({
subset(selectedData, route_id == input$route)
})
a <- reactive({
aggregate(input$rider~input$id,data,input$method)
})
s <- reactive({input$rider})
output$plot1 <- renderPlot({barplot(a[s])})
}
But I am getting the following error: 但是我收到以下错误:
Error: object of type 'closure' is not subsettable
Please help me with this . 请帮我解决一下这个 。 I am new to shiny.
我很有光泽。
You should access to reactive expression as a function, so you need to add ()
to any call to a variable created as a reactive expression. 您应该将反应式表达式作为函数访问,因此您需要将
()
添加到对作为反应式表达式创建的变量的任何调用。
Instead of: 代替:
subset(selectedData, route_id == input$route)
try using: 尝试使用:
subset(selectedData(), route_id == input$route)
or even use a extra variable to avoid problems. 甚至使用额外的变量来避免问题。
selectedData_ <- selectedData()
subset(selectedData_, route_id == input$route)
Finally, you don't need to put a single input
into a reactive expression, just used it into any other reactive expression as renderPlot
. 最后,您不需要将单个
input
放入反应式表达式中,只需将其用作任何其他反应式表达式作为renderPlot
。
Insted of 绝缘
s <- reactive({input$rider})
output$plot1 <- renderPlot({barplot(a[s])})
Use only 仅限使用
output$plot1 <- renderPlot({
a_ <- a()
barplot(a_[input$rider])
})
Please note that since you didn't provide any representative data for y
, I was unable to test your code completely, but this answer should resolve the closure error. 请注意,由于您没有提供
y
任何代表性数据,我无法完全测试您的代码,但此答案应解决关闭错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.