Does anyone know how to disable outputs if error messages come up on Shiny app?

on my shiny app, if a user inputs invalid numbers into the input tab, they will get error messages back, however, the output is still visible. I am wondering if there is any way that the output can be disabled if error messages come up?

Here is the code for error messages:


              need((input$N_2 != ""), "Please fill in all of the boxes") %then%
                need((input$sigma_1 >= 0), "Standard deviation 1 must be positive.") %then%
                need((input$sigma_2 >= 0), "Standard deviation 2 must be positive.") %then%
                need(all.equal(input$N_1, as.integer(input$N_1)) == TRUE, "Sample size 1 must be an integer.") %then%
                need((input$N_1 >= 1), "Sample size 1 must be 1 or greater.") %then%
                need(all.equal(input$N_2, as.integer(input$N_2)) == TRUE, "Sample size 2 must be an integer.") %then%
                need((input$N_2 >= 1), "Sample size 2 must be 1 or greater.")
            data_grp1 = rnorm(n = input$N_1, mean = input$mu_1, sd = input$sigma_1)
            data_grp2 = rnorm(n = input$N_2, mean = input$mu_2, sd = input$sigma_2)

The codes for the output are pretty lengthy as there is a code for the text output, a long code for a histogram, and some plots.

here is the code for the summary output:

output$summary <- renderText ({ 
        paste(sep = "", "Based on population means of <b>", input$mu_1, "</b> and <b>", input$mu_2, 
              "</b>, population standard deviations of <b>", input$sigma_1, "</b> and <b>", input$sigma_2, 
              "</b>, sample sizes of <b>", input$N_1, "</b> and <b>", input$N_2, "</b>, and alpha of <b>", 
              input$alpha, "</b>, the estimated power of the <b>", ifelse(input$tail=='two.sided', 'two-tailed', 
                                                                          ifelse(input$tail=='greater', 'upper-tailed', 'lower-tailed')), "</b> independent samples t-test is <b>", 
              round(Power, digits = 2), "</b>, with a range of <b> [", round(minrange, digits = 2), ", ", 
              round(maxrange, digits = 2), "]</b>.") 
    Power = tail(outer_results$Updated_Power, n = 1)
  paste(sep = "", "Est. Power = ", round(Power, digits = 2))

You can put a required statement at the first line in your renderText


You can also return informative messages to the user with validate.

1 Like