在我的 Shiny 应用程序中,我的用户可以从服务器上传文件以查看结果。我让用户使用 selectInput 选择文件,然后他们单击 actionButton 加载文件。我还希望用户能够删除文件和添加新文件,并且我已经使用单独的 actionButtons 成功地进行了设置。当用户删除或添加文件时,我想更新 selectInput 以便删除的文件不再存在,而添加的文件则存在。我在我的 observeEvent 代码中使用 updateSelectInput 尝试了这个,但它不起作用。这是我的删除文件部分的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
})
Run Code Online (Sandbox Code Playgroud)
当我运行包含此代码的应用程序时,会发生两件事。在应用程序窗口中,我在 input_file 小部件的正上方看到以下文本:[object Object 在我的 R 控制台中,我得到:
asJSON(keep_vec_names=TRUE) 的输入是一个命名向量。在未来的 jsonlite 版本中,将不支持此选项,命名向量将被转换为数组而不是对象。如果您想要 JSON 对象输出,请改用命名列表。见?toJSON。
我已经session在我的 ShinyServer 调用中包含了参数:
shinyServer(function(input, output, session)
Run Code Online (Sandbox Code Playgroud)
任何意见,将不胜感激。
我发现一个极端的情况也会导致这个错误。在我的代码的不相关区域放入tabPanel()a后renderUI(), an就停止工作了。updateSelectInput
要解决此问题,请将 tabPanel 保留在 ui.R 中,并renderUI()在函数内进行调整,而不是将其全部放入 server.R 中,如下所示:updateSelectInput 操作顺序/竞争条件