ANOVA闪亮的应用程序

 youth冰点 发布于 2023-01-10 11:50

我试图让这个ANOVA闪亮的应用程序运行没有运气.输出应该是一个列表,所以我可能会对如何输出这些数据类型感到困惑.有什么建议?

server.R

library(shiny)
library(car)

shinyServer(function(input, output) {

  csvfile <- reactive({

    csvfile <- input$file1
    if (is.null(csvfile)){return(NULL)}
    dt <- read.csv(csvfile$datapath, header=input$header, sep=input$sep)
    dt

  })

  output$var <- renderUI({

     if(is.null(input$file1$datapath)){return()}

     else list (

       radioButtons("dvar", "Please Pick The Dependent Variable", choices =    names(csvfile())),
       radioButtons("ivar", "Please Pick The Independent Variable", choices = names(csvfile())),
      actionButton("submit", "Submit")

     )
  })

  output$aovSummary = renderTable({
    if (is.null(input$file1$datapath)){return()}

    if (input$submit > 0) {

      if (input$type == 'type1'){

        isolate(anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile()))

  }

  if (input$type == 'type2'){

    isolate(Anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile()), Type = "II", test.statistic = "F"))

      }

      if (input$type == 'type3'){

        isolate({
          fit <- aov(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile()))
          drop1(fit, ~ . , test = 'F')
        })

      }

    }})

})

ui.R

library(shiny)

shinyUI(pageWithSidebar(

  headerPanel('Analysis of Variance'),

  sidebarPanel(

    fileInput("file1", "CSV File", accept=c("text/csv", "text/comma-separated-values,text/plain", ".csv")),

    checkboxInput("header", "Header", TRUE),

    radioButtons('sep', 'Separator',
             c(Comma=',',
               Semicolon=';',
               Tab='\t'),
             ','),

    selectInput('type', 'Please select Sums of Squares type', 
            c(I = 'type1', II = 'type2', III = 'type3'), 'type1'),

    uiOutput('var')

  ),

  mainPanel(

    h3('ANOVA Table'),
    verbatimTextOutput('aovSummary')

  )
))

在此先感谢您的帮助.

1 个回答
  • 我试着运行你的代码.有格式问题.下面的代码适用于我.我没有csv测试它,但它可能适合你.

    library(shiny)
    library(car)
    
    runApp(
      list(
        ui = pageWithSidebar(
          headerPanel('Analysis of Variance'),
          sidebarPanel(
            fileInput("file1", "CSV File", accept=c("text/csv", "text/comma-separated-values,text/plain", ".csv")),
            checkboxInput("header", "Header", TRUE),
            radioButtons('sep', 'Separator',c(Comma=',',Semicolon=';',Tab='\t'),','),
            selectInput('type', 'Please select Sums of Squares type', 
                        c(I = 'type1', II = 'type2', III = 'type3'), 'type1')
            ,uiOutput('var') 
          )
          , mainPanel(    
            h3('ANOVA Table'),
            tableOutput('aovSummary')
          )
        )
        , server = function(input, output, session) {
          csvfile <- reactive({
            csvfile <- input$file1
            if (is.null(csvfile)){return(NULL)}
            dt <- read.csv(csvfile$datapath, header=input$header, sep=input$sep)
            dt
          })
          output$var <- renderUI({
            if(is.null(input$file1$datapath)){
              return()
            }else{
              list (radioButtons("dvar", "Please Pick The Dependent Variable", choices =    names(csvfile())),
                    radioButtons("ivar", "Please Pick The Independent Variable", choices = names(csvfile())),
                    actionButton("submit", "Submit")
              )
            }
          })
    
          output$aovSummary = renderTable({
            if(is.null(input$file1$datapath)){return()}
            if(input$submit > 0){
              if(input$type == 'type1'){
                return(isolate(anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile()))))
              }
              if(input$type == 'type2'){
                return(isolate(Anova(lm(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile())), Type = "II", test.statistic = "F"))
              }
              if(input$type == 'type3'){
                isolate(
                  fit <- aov(csvfile()[,input$dvar] ~ csvfile()[,input$ivar], data = csvfile())
                )
                return(drop1(fit, ~ . , test = 'F'))
              }
            }
          })
        })
    )
    

    2023-01-10 11:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有