2016-10-21 44 views
1

我正在嘗試使用R閃亮創建圖形應用程序。因此,我從用戶那裏接受來自用戶的路線,停車/旅行ID(登機,下車或載重)的輸入。所以ui.r是「閉包」類型的對象不可子集: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') 

    ) 
) 
) 

然後我試圖提取特定的路線,例如用stop_id登機,並試圖爲那些stop_id一個barplot合計值的數據。該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])}) 

} 

但我收到以下錯誤:

Error: object of type 'closure' is not subsettable 

請幫助我。我是新來的閃亮。

回答

0

您應該訪問作爲函數的反應表達式,因此您需要將()添加到對作爲反應表達式創建的變量的任何調用中。

相反的:

subset(selectedData, route_id == input$route)

嘗試使用:

subset(selectedData(), route_id == input$route)

甚至使用一個額外的變量,以避免出現問題。

selectedData_ <- selectedData() 
subset(selectedData_, route_id == input$route) 

最後,你不需要把一個單一input爲反應性的表情,只是用它到任何其他反應表達renderPlot

s <- reactive({input$rider}) 
output$plot1 <- renderPlot({barplot(a[s])}) 

使用insted的唯一

output$plot1 <- renderPlot({ 
    a_ <- a() 
    barplot(a_[input$rider]) 
}) 

請注意,因爲你沒有爲y提供任何代表性的數據,我無法徹底測試你的代碼,但這個答案應該解決關閉錯誤。

相關問題