

# Hypothesis Testing of Means: Two Samples, Unknown Equal Variance
# Shiny server for Two-sample t-test


shinyServer(function(input, output) {


      inputVal_eventReactive <- eventReactive(input$cmdUpdate, {
        
        
            iseed <- input$numRN + (as.integer(input$cmdUpdate) - 1)
            
            pmean1 <- input$pmean1
            pmean2 <- input$pmean2
            
            psd <- input$psd
            
            n1 <- input$n1
            n2 <- input$n2
            
            p <- input$p  # user probability
            p_tail <- input$p_prob_type
            
            fn_InputData_repeatable <- repeatable(rngfunc = fn_InputData, seed = iseed)
            
            fn_InputData_repeatable(pmean1 = pmean1, pmean2 = pmean2,
                                    psd = psd,
                                    n1 = n1, n2 = n2,
                                    p = p, p_tail = p_tail)
        

      })




      inputVal_reactive <- reactive({
        
            pmean1 <- input$pmean1
            pmean2 <- input$pmean2
            
            psd <- input$psd
            
            n1 <- input$n1
            n2 <- input$n2
            
            p <- input$p  # user probability
            p_tail <- input$p_prob_type
            
            fn_InputData(pmean1 = pmean1, pmean2 = pmean2,
                         psd = psd,
                         n1 = n1, n2 = n2,
                         p = p, p_tail = p_tail)
        
        
      })
      





      output$dnorm_plot <- renderPlot({

          if(input$chkUpdate){
  
            fn_dnorm(inputVal_reactive())
  
          } else {
  
            fn_dnorm(inputVal_eventReactive())
  
          }


      })



      output$dotplot <- renderPlot({

          if(input$chkUpdate){
  
            fn_dotplot(inputVal_reactive())
  
          } else {
  
            fn_dotplot(inputVal_eventReactive())
  
          }


      })




      output$boxplot <- renderPlot({

          if(input$chkUpdate){
  
            fn_boxplot(inputVal_reactive())
  
          } else {
  
            fn_boxplot(inputVal_eventReactive())
  
          }


      })



      output$mdiff_plot1 <- renderPlot({

          if(input$chkUpdate){
  
            fn_mean_diff(inputVal_reactive())
  
          } else {
  
            fn_mean_diff(inputVal_eventReactive())
  
          }


      })



      output$dt_plot1 <- renderPlot({

          if(input$chkUpdate){
  
            fn_dt_plot1(inputVal_reactive())
  
          } else {
  
            fn_dt_plot1(inputVal_eventReactive())
  
          }


      })




      output$H <- renderUI({
        if(input$chkUpdate){
          fn_Report(inputVal_reactive())[['H']]
        } else {
          fn_Report(inputVal_eventReactive())[['H']]
        }
      })

      
      
      dt_sample <- renderTable({
          if(input$chkUpdate){
            fn_Report(inputVal_reactive())[['sDF']]
          } else {
            fn_Report(inputVal_eventReactive())[['sDF']]
          }
      }, striped = TRUE, hover = TRUE, bordered = TRUE, align = 'c')  
 
      output$dt_sample <- renderUI(fluidPage(dt_sample, style="overflow-y:scroll; height: 300px"))
      


      output$dt_sstat <- renderTable({
          if(input$chkUpdate){
            fn_Report(inputVal_reactive())[['sstat']]
          } else {
            fn_Report(inputVal_eventReactive())[['sstat']]
          }
      }, striped = TRUE, hover = TRUE, bordered = TRUE, align = 'c')


      
      output$dt_tstat <- renderTable({
          if(input$chkUpdate){
            fn_Report(inputVal_reactive())[['tstat']]
          } else {
            fn_Report(inputVal_eventReactive())[['tstat']]
          }
      }, striped = TRUE, hover = TRUE, bordered = TRUE, align = 'c')  
      


      output$CI <- renderUI(
          if(input$chkUpdate){
            fn_Report(inputVal_reactive())[['txtCI']]
          } else {
            fn_Report(inputVal_eventReactive())[['txtCI']]
          }
      )
      

})

