5

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.

2
  • 8
    Try naming your arguments. updateSelectInput(session= session, inputId = "input_file", choices = choices). Using positional matching, the third argument in updateSelectInput is label, so you aren't actually changing the choices, but trying to assign a vector to the label. Commented Apr 5, 2016 at 16:21
  • That was it! If you put your comment in an answer, I'll check it off. Commented Apr 5, 2016 at 16:39

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Seems like the corner case is true. How do you manage this if you are forced to take everything inside server.R because access to reactive variables are key. and @hedge did you raise an issue on github? Do the shiny developers know about this?
not sure. Did not raise an issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.