首页 > 解决方案 > 用户上传文件的统计测试

问题描述

我目前正在尝试开发一个可以对用户上传的任何文件进行统计测试的应用程序。问题是我经常在尝试进行测试时遇到问题,并且出现许多“错误”消息。例如,在这里我无法进行 t 检验。请您在我的代码中查找错误,因为我自己似乎无法找到它们。此外,如果您有任何其他代码建议可能类似于我正在尝试创建的应用程序,我很乐意看到它们以获得一些灵感并更好地了解 Shiny 的工作原理。这是我的代码的开头,非常感谢您的关注。

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)```

标签: rfile-uploadshinyshinyappsstatistical-test

解决方案


推荐阅读