Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updateSelectinput throws a session not found error

Tags:

r

shiny

I am using this code, and keep running into a Error in updateSelectInput: object 'session' not found. This happens when I try to upload any file, through the fileInput option. When I remove the updateSelectInput statement, the table prints fine. (Note that Im providing the bare minimum code necessary to reproduce the problem, the code doesnt include portions where I expect to use the SelectInput inputs).

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
like image 214
ashleych Avatar asked Oct 14 '17 20:10

ashleych


1 Answers

The server function is missing the session argument:

server <- function(input, output, session)
like image 58
greg L Avatar answered Nov 09 '22 17:11

greg L