我正在使用此代码,并且在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
答案 0 :(得分:8)
服务器功能缺少session
参数:
server <- function(input, output, session)
答案 1 :(得分:-1)
如果你的代码包含输入元素,你可以试试这个:
server <- function(input, output,session){
options(shiny.maxRequestSize=10*1024^2)
data_input <- reactive({
req(input$csv_input)
fread(input$csv_input$datapath)
})
observeEvent(data_input(),{
choices <- c(not_sel,names(data_input()))
updateSelectInput(session, inputId = "num_var_1", choices = choices)
updateSelectInput(session, inputId = "num_var_2", choices = choices)
updateSelectInput(session, inputId = "fact_var", choices = choices)
})