dimanche 5 août 2018

How can I fade out or make text output disappear if certain input conditions are not met?

I am wondering how I can make my summary text-output either gray out or disappear altogether if a user inputs invalid numbers into the input bar?

isolate({

    validate(

      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.")

    )

What is in quotation marks are my error messages. So for example, if a user inputs a negative SD for group 1, they will get an error message back saying that the SD must be positive.

This is how the output currently looks:

As you can see, on the right, the error message (in the black on top) shows up, but it would make more sense to have the rest of the summary output below, including the range estimation, grayed out or disappear if an error message pops up.

Here is the code for the summary output:

  paste(sep = "", "Est. Power Range = [", round(minrange, digits = 2), 
        ", ", round(maxrange, digits = 2), "]")
})


#---
# Create a dynamic summary sentence based on the inputs and the power and range
#---

output$summary <- renderText ({ 
  isolate({ 
    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>.") 
  }) 
})

I am thinking it would be some sort of if-then statement?

Thank you so much in advance!

Aucun commentaire:

Enregistrer un commentaire