0

I would like to display an error message in my shiny app if it's impossible to build the table (because of the selected criteria) :

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  
})

This doesn't work, if the table is impossible to build then the R error message is displayed instead of the desired one :

Error : Problem with filter() input ..1. [34mi[39m Input ..1 is &.... [31mx[39m Input ..1 must be of size 741 or 1, not size 0.

1 Answer 1

0

You can do a conditional return within renderTable that checks if your input is valid (do that however is appropriate given these input objects - we can't know without seeing the code) and, if not, return a message instead.

Something like this:

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)
  }
})

I think you'll need to put the 'error' message in a table to print since it is in renderTable so when I do this I just make a little tibble with a column called 'Issue' or something (or you can name it something from tab_taux to make it match, but with a message inside saying to reselect or something)

Not the answer you're looking for? Browse other questions tagged or ask your own question.