gpt4 book ai didi

r - 方差分析 Shiny 的应用程序

转载 作者:行者123 更新时间:2023-12-01 15:43:33 26 4
gpt4 key购买 nike

我正试图让这个 ANOVA Shiny 应用运行起来,但运气不好。输出应该是一个列表,所以我可能对如何输出这些数据类型感到困惑。有什么建议吗?

服务器.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')

)
))

在此先感谢您的帮助。

最佳答案

我试着运行你的代码。存在格式问题。下面的代码为我运行。我没有用于测试它的 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'))
}
}
})
})
)

关于r - 方差分析 Shiny 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24123895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com