我正在尝试构建一个Shiny应用程序,对用户可以选择的变量进行单向ANOVA测试。我创建了一个虚拟数据集,用1个连续变量和1个分类变量来说明错误。
我得到的错误是: 对比只能适用于具有2级或更多级别的因素
当我在它上面运行aov(contVars ~ factorVars, testtable)
时,我得到了预期的输出。但是,当它被放入Shiny应用程序时,它就好像无法识别因子向量类型。
#load libraries
library(shiny)
testtable <- data.frame(externalVars = round(runif(20)*10,0), factorVars = gl(5,4))
#functions here
ui <- fluidPage(
column(3,
uiOutput("selectfactorVars"),
uiOutput("selectcontVars")
), # close column
column(9,
h3("ANOVA results"),
uiOutput("displayOutput")
) # close column
) # close fluidPage
server <- function(input, output, session){
output$selectfactorVars <- renderUI({
selectInput(
inputId="factorVars",
label="Select continuous variables",
choices=names(testtable)
) # close selectInput
}) # close renderUI
output$selectcontVars <- renderUI({
selectInput(
inputId="contVars",
label="Select continuous variables",
choices=names(testtable)
) # close selectInput
}) # close renderUI
render.react <- reactive({
# this is where the error occurs, works fine if I just print the variables
fit <- stats::aov(input$contVars ~ input$factorVars, testtable)
}) # close reactive
output$displayOutput <- renderPrint({
render.react()
}) # close renderPrint
} # close server
shinyApp(ui=ui, server=server)