2017-10-14 83 views
1

我正在使用此代碼,並繼續運行updateSelectInput中的錯誤:找不到對象'會話'。當我嘗試通過fileInput選項上載任何文件時會發生這種情況。當我刪除updateSelectInput語句時,表格打印正常。 (請注意,Im提供重現問題所需的最低代碼,代碼不包含我期望使用SelectInput輸入的部分)。updateSelectinput引發會話未找到錯誤

library(shiny); library(shinythemes); library(DT) 

ui<- fluidPage(
    sidebarLayout(
    sidebarPanel(
     fileInput(inputId = "default_csv",label="input the file"), 
     selectInput(inputId = "facility_id1", label="Choose the facilityID column", choices ="FacilityID"), 
     numericInput(inputId = "obs", label="Choose number of obs", value=10) 
    ), 
    mainPanel(
     dataTableOutput(outputId = "table") 
    ) 
) 
) 



server<- function(input, output){ 

    data_set <- reactive({ 
    data_set<-read.csv(input$default_csv$datapath, stringsAsFactors = FALSE) 
    }) 
    observe({ 
    req(input$default_csv) 
    dsnames <- names(data_set()) 

    updateSelectInput(session, "facility_id1", label = "Facility ID", 
         choices = dsnames, selected = "") 

    cat("update done") 
    }) 
    output$table<- renderDataTable(head(data_set(),n=input$obs)) 
} 

shinyApp(ui=ui, server=server) 

Warning: Error in updateSelectInput: object 'session' not found 
Stack trace (innermost first): 
    57: updateSelectInput 
    56: observerFunc [C:/Users/APTIVAA/Desktop/9.R#29] 
    1: runApp 
ERROR: [on_request_read] connection reset by peer 

回答

4

服務器功能缺少session說法:

server <- function(input, output, session) 
+0

巴掌額頭。 – ashleych