RenderUI resetting to default and not holding inputs

438 views
Skip to first unread message

Allison Theobold

unread,
Jul 21, 2015, 11:07:11 AM7/21/15
to shiny-...@googlegroups.com
Hello everyone! 

I apologize for the bother, but I seem to be struggling with a renderUI not holding input values and automatically resetting to the default value once a task is completed. 

I am working on designing a website for the Intro Statistics course at Montana State University. For the 1-Categorical variable input, we are using a permutation test to test if p=p_0. I have the user input the value of the null hypothesis (p_0) and then generate random binomials with that probability. Then the user chooses what direction(s) they wish to use to calculate the p-value and it outputs on the screen. 

The problem: We have set the default value of p_0 to 0.5. Once the user changes it to say, 0.4, generates shuffles, and then calculates the p-value, the renderUI automatically resets the value of p_0 to 0.5 and the plot goes away. 

Below is the code (can also be found in Github under jimrc, IntroStatShinyApps), with the problem section commented out in maroon:

 output$cat1_testUI <- renderUI({
   
if( is.null(cat1_data$counts)){
     h4
(" You must first enter data. Choose 'Enter/Describe Data'.")
   
} else {
    tabPanel
("Test", value="1catTest",
             titlePanel
("Test for a Single Proportion"),      
             fluidRow
(
               column
(4,
                      h3
("Original Data"),
                      tableOutput
("cat1OriginalData"),
                     
                      h3
("Shuffled Sample"),
                      tableOutput
('cat1Test_Table'),
                     
                      br
(),
                     
                      h5
("We start showing one sample from the null."),
                      h5
("How many more?"),
                     
                      actionButton
("cat1_test_shuffle_10", label = "10"),
                      actionButton
("cat1_test_shuffle_100", label = "100"),
                      actionButton
("cat1_test_shuffle_1000", label = "1000"),
                      actionButton
("cat1_test_shuffle_5000", label = "5000")
             
),
                     
               column
(8,
 #####                     sliderInput("null_p", "Choose true proportion of successes ",
 
#####                                                 min= 0, max = 1, value = .5)
,
                     
                      plotOutput
('cat1Test_Plot2', click = 'cat1_Test_click'),
                     
                      br
(),
                      br
(),
                      br
(),
                     
                      h4
("Count values "),
                      fluidRow
(
                        column
(4,
                               selectInput
('cat1_testDirection', label = "",
                                           choices
= list("less", "more extreme", "greater"),
                                           
select = "more extreme", selectize = FALSE, width = 200)
                       
),
                        column
(2, h4(" than ")),
                        column
(3,
                               textInput
('cat1_test_cutoff', label = "", value = NA)),
                        column
(2,
                               actionButton
('cat1_test_countXtremes', "Go"))
                     
),
                     
                     
if(!is.null(cat1Test$moreExtremeCount)){
                        h4
(paste("There are ", cat1Test$moreExtremeCount, " / ", length(cat1Test$phat), input$cat1_testDirection,
                                 
" than ", cat1Test$cutoff, " , p-value = ", round(cat1Test$pvalue, 5)))
                     
} else { h4(" ")}
               
)
             
)
   
)
   
}
 
})




Is there a way to get the renderUI to hold the input value and not automatically reset?

Thank you for your time!

Allison Theobold

Joe Cheng

unread,
Jul 21, 2015, 12:35:22 PM7/21/15
to Allison Theobold, shiny-...@googlegroups.com
This is happening because the entire renderUI block executes whenever something in it changes; in this case I'd assume it is one or more of the values in this block:

if(!is.null(cat1Test$moreExtremeCount)){
  h4(paste("There are ", cat1Test$moreExtremeCount, " / ", length(cat1Test$phat), input$cat1_testDirection, 
    " than ", cat1Test$cutoff, " , p-value = ", round(cat1Test$pvalue, 5)))
} else { h4(" ")}

I think if you replaced that with its own uiOutput() (you can embed uiOutput in the renderUI you are already using) the problem should go away.


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/0a13f3cf-a602-41a4-a18e-7fcb435c17b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages