简体   繁体   English

观察事件中的 R 闪亮 updateSelectInput 不起作用

[英]R shiny updateSelectInput in observeEvent not working

In my Shiny app my users can upload a file from the server to view the results.在我的 Shiny 应用程序中,我的用户可以从服务器上传文件以查看结果。 I have the user select the file using a selectInput, and then they click an actionButton to load the file.我让用户使用 selectInput 选择文件,然后他们单击 actionButton 加载文件。 I also want users to be able to delete files and add new files, and I've set that up successfully using separate actionButtons.我还希望用户能够删除文件和添加新文件,并且我已经使用单独的 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.当用户删除或添加文件时,我想更新 selectInput 以便删除的文件不再存在,而添加的文件则存在。 I tried this using updateSelectInput in my observeEvent code but its not working.我在我的 observeEvent 代码中使用 updateSelectInput 尝试了这个,但它不起作用。 Here's my observeEvent for the delete file portion:这是我的删除文件部分的observeEvent:

  #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_file 小部件的正上方看到以下文本: [object Object在我的 R 控制台中,我得到:

Input to asJSON(keep_vec_names=TRUE) is a named vector. asJSON(keep_vec_names=TRUE) 的输入是一个命名向量。 In a future version of jsonlite, this option will not be supported, and named vectors will be translated into arrays instead of objects.在未来的 jsonlite 版本中,将不支持此选项,命名向量将被转换为数组而不是对象。 If you want JSON object output, please use a named list instead.如果您想要 JSON 对象输出,请改用命名列表。 See ?toJSON.见?toJSON。

I have included the session parameter in my shinyServer call:我在我的 ShinyServer 调用中包含了session参数:

shinyServer(function(input, output, session)

Any advice would be appreciated.任何建议将不胜感激。

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.tabPanel()放入renderUI() ,我代码中不相关区域中的updateSelectInput停止工作。

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要解决此问题,请将 tabPanel 留在 ui.R 中,并使用renderUI()在函数内进行调整,而不是将其全部放入 server.R,如下所示: updateSelectInput order of operations/race condition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM