【问题标题】:R shiny updateSelectInput in observeEvent not working观察事件中的R闪亮updateSelectInput不起作用
【发布时间】: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
  • 就是这样!如果您将评论放在答案中,我会检查它。

标签: r shiny


【解决方案1】:

我发现了一个也导致此错误的极端案例。将tabPanel() 放入renderUI() 后,我的代码无关区域中的updateSelectInput 就停止了工作。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-17
    • 2021-05-17
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 2015-10-01
    • 2018-05-26
    相关资源
    最近更新 更多