0

I am currently trying to develop an app that could realise statistical tests on any file uploaded by the user. The problem is that I often encounter problems trying to do the tests and many "error" messages appears. Here I cannot make the t-test work for example. Would you kindly care to look for the errors in my code please, as I cannot seem to find them myself. Moreover, if you by any chance have any other codes to suggest that could resemble the app I am trying to create I would gladly like to see them to get some inspiration and better understand how Shiny works. Here is the beginning of my code, Thank you so much for your attention.

library(ggplot2)
library(desctable)
ui <- fluidPage(
  tabPanel(
    "Upload File",
    titlePanel("Uploading Files"),
    sidebarLayout(
      sidebarPanel(
        fileInput('file1', 'Choose CSV File', min=0 , max=1000 , value=500
                  accept=c('.csv')),
        checkboxInput('header', 'Header', TRUE),
        radioButtons('sep', 'Separator',
                     choices = c(Comma=',', Semicolon=';', Tab='\t'),
                     selected = ','),
        
        selectInput('xcol', 'X Variable', "", selected = NULL),
        selectInput('ycol', 'Y Variable', "", selected = NULL),
        selectInput("method", "Select t test type", 
                    c("One-sample t test",
                      "Independent two-sample t test"
                    ),
                    
        ),
        mainPanel(
         
          plotOutput('MyPlot'),
          tableOutput("table"),
          verbatimTextOutput("summary")
        )
      )
    )
  )
  
  server <- function(input, output, session)
  {
    output$table<- renderDataTable(input$file1)
    
    myfiles <- reactive({
      req(input$file1$datapath, file.exists(input$file1$datapath))
      
read.csv(input$file1$datapath)
    })
output$summary<-renderPrint(myfiles%>%desctable(stars=list((“N”  =length,
       “Moyenne”= is.normal~mean,
“Médiane”=median,
“MAD”=mad))    
  observeEvent(myfiles(), {
      req(myfiles())
      nms <- colnames(myfiles())
      updateSelectInput(
        session, 
        inputId = 'xcol', 
        label = 'X Variable',
        choices = nms, selected = nms[1]
      )
      
      updateSelectInput(
        session, 
        inputId = 'ycol', 
        label = 'Y Variable',
        choices = nms, selected = nms[1]
      )
    })
    
    output$table <- renderTable({
      if(is.null(dff())){return ()}
      
      if(input$method == "One-sample t test"){
        t.test(myfiles[input$xcol], mu = as.numeric(input$mu))
        
       else if (input$method == "Independent two-sample t test"){
        t.test(input$xcol ~ input$ycol, data = myfiles)}
        
        output$MyPlot <- renderPlot({
          req(myfiles(), input$xcol, input$ycol)
          ggplot(data = myfiles(), mapping = aes_string(input$xcol, input$ycol)) +
            geom_point() +theme_dark()
           
        })}
      
      
      shinyApp(ui , server)```
  • `output$table` is used twice (need to be unique), may need `req()` in the first one, and where is `dff()` object defined? – YBS Jan 30 '21 at 20:48
  • Welcome to SO, HanaeLevy! If you have errors, please don't make us guess at them or make us run things just to find your errors, please just [edit] your question and add the literal text of the errors/warnings (in a code-block). Also, as @YBS suggested, it appears that your code may be incomplete. – r2evans Jan 30 '21 at 21:05
  • Thank your for your post. Would be nice to have the file and see how the app behaves in the first hand. Can you share the file or create a pseudoreplicate? – LDT Jan 30 '21 at 22:46

0 Answers0