【发布时间】:2016-07-25 15:19:59
【问题描述】:
在我的 Shiny 应用中,我的用户可以从服务器上传文件以查看结果。我让用户使用 selectInput 选择文件,然后他们单击 actionButton 来加载文件。我还希望用户能够删除文件和添加新文件,并且我已经使用单独的 actionButtons 成功地进行了设置。当用户删除或添加文件时,我想更新 selectInput 以便删除的文件不再存在,并且添加的文件存在。我在我的 observeEvent 代码中使用 updateSelectInput 进行了尝试,但它不起作用。这是删除文件部分的观察事件:
#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
})
当我运行包含此代码的应用程序时,会发生两件事。在 App 窗口中,我在 input_file 小部件的正上方看到了以下文本:[object Object 在我的 R 控制台中,我得到:
asJSON(keep_vec_names=TRUE) 的输入是一个命名向量。在未来 jsonlite 版本,不支持此选项,并命名为 向量将被转换为数组而不是对象。如果你想 JSON 对象输出,请改用命名列表。请参阅 ?toJSON。
我在 shinyServer 调用中包含了session 参数:
shinyServer(function(input, output, session)
任何建议将不胜感激。
【问题讨论】:
-
尝试命名你的论点。
updateSelectInput(session= session, inputId = "input_file", choices = choices)。使用位置匹配,updateSelectInput中的第三个参数是label,因此您实际上并没有更改选择,而是尝试将向量分配给label。 -
就是这样!如果您将评论放在答案中,我会检查它。