Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shiny updateSelectInput in observeEvent not working

Tags:

r

shiny

In my Shiny app my users can upload a file from the server to view the results. I have the user select the file using a selectInput, and then they click an actionButton to load the file. I also want users to be able to delete files and add new files, and I've set that up successfully using separate actionButtons. When the user deletes or adds a file I want to update the selectInput so the deleted files aren't there anymore, and the added files are. I tried this using updateSelectInput in my observeEvent code but its not working. Here's my observeEvent for the delete file portion:

  #Delete parameter files
  observeEvent(input$delete,{
    file.remove(input$input_file) #deletes the file selected in the input_file widget
    choices <- list.files("C:/Users/shiny/testapp/", pattern="*.Rdata")
    updateSelectInput(session,"input_file",choices) #supposed to update the input_file widget
  })

When I run the app with this code in it, two things happen. In the App window, I get this text right above the input_file widget: [object Object And in my R console I get:

Input to asJSON(keep_vec_names=TRUE) is a named vector. In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects. If you want JSON object output, please use a named list instead. See ?toJSON.

I have included the session parameter in my shinyServer call:

shinyServer(function(input, output, session)

Any advice would be appreciated.

like image 409
robin.datadrivers Avatar asked Nov 09 '22 17:11

robin.datadrivers


1 Answers

I found a corner case that also causes this bug. Upon putting tabPanel() in a renderUI(), an updateSelectInput in an unrelated area of my code just stopped working.

To resolve, leave the tabPanel in ui.R, and use renderUI() to adjust within the function instead of bringing it all into server.R, like here: updateSelectInput order of operations/race condition

like image 168
hedgedandlevered Avatar answered Nov 15 '22 07:11

hedgedandlevered