【问题标题】:Display an error message in a RenderTable Rshiny在 RenderTable R Shiny 中显示错误消息
【发布时间】:2023-04-05 23:46:01
【问题描述】:

如果无法构建表格(由于所选标准),我想在闪亮的应用程序中显示错误消息:

output$tableau_taux <- renderTable({
    tab_taux <- NULL
    tab_taux <- tableau_taux_fonction(input$etab_id,input$pcs_id,input$retard_id,input$sexe_id)
    validate(
      need(!is.null(tab_taux), "Veuillez sélectionner d'autres critères")
    )
    tab_taux  
})

这不起作用,如果无法构建表,则会显示 R 错误消息而不是所需的消息:

错误:filter() 输入 ..1 有问题。 [34mi[39m 输入..1&amp;...。 [31mx[39m 输入..1 的大小必须是 741 或 1,而不是大小 0。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您可以在renderTable 中执行条件返回,以检查您的输入是否有效(但鉴于这些输入对象,这样做是合适的 - 我们不看代码就无法知道),如果不是,则返回一条消息.

    类似这样的:

    output$tableau_taux <- renderTable({
      # check if input works for your function
      # add additional/complete/appropriate checks here as needed - just an example
      if(length(input$etab_id) == 0){
        print(dplyr::tibble("Issue" = "Veuillez sélectionner d'autres critères"))
      } else {
        tab_taux <- tableau_taux_fonction(input$etab_id,input$pcs_id,input$retard_id,input$sexe_id)
        print(tab_taux)
      }
    })
    

    我认为您需要将“错误”消息放在要打印的表格中,因为它在 renderTable 中,所以当我这样做时,我只是用一个名为“问题”的列或其他东西(或您可以从 tab_taux 中为其命名以使其匹配,但在里面有一条消息说要重新选择或其他东西)

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 1970-01-01
      • 2021-08-04
      • 2021-02-11
      • 1970-01-01
      • 2013-03-08
      • 2015-09-02
      • 2014-01-07
      • 2022-01-18
      相关资源
      最近更新 更多