我正在使用此代码,并在updateSelectInput中遇到错误:找不到对象'session'.当我尝试通过fileInput选项上传任何文件时会发生这种情况.当我删除updateSelectInput语句时,表打印正常.(请注意,我提供了重现问题所需的最小代码,代码中不包含我希望使用SelectInput输入的部分).
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//Desktop/9.R#29]
1: runApp
ERROR: [on_request_read] connection reset by peer
Run Code Online (Sandbox Code Playgroud)
gre*_*g L 11
服务器函数缺少session参数:
server <- function(input, output, session)
Run Code Online (Sandbox Code Playgroud)