data(mtcars)
library(stats)
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectizeInput("mtcarsid", "Nehme eine MT Cars category.", choices = colnames(mtcars), selected = colnames(mtcars)[2], multiple = FALSE)
),
# Show a plot of the generated distribution
mainPanel(
tableOutput("model"),
textOutput("text123")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$text123 <- renderText({
})
output$model <- renderTable ({
z <- factor(input$mtcarsid)
# #print(mtcars[[z]])
#
# print(length(mtcars$mpg))
#
# print(length(mtcars[[z]]))
x <- aov(mpg ~ factor(mtcars[[z]]), data=mtcars)
x <- TukeyHSD(x)
print(x)
x <- as.data.frame(x[[1]][,4] > 0.05)
x
})
}
# Run the application
shinyApp(ui = ui, server = server)
这是我的应用程序,基于我要输入的$ mtcarsid的输入,我想执行方差分析。事后测试。但是,我的模型似乎完全错误地输入了我的代码。谁能告诉我为什么?
aov(mpg ~ factor(cyl), data = mtcars)
此代码可以正常工作。但是,当我只使用factor(input $ mtcarsid)时,我得到一个错误,即输入长度不同(1 vs 32)。
答案 0 :(得分:0)
一种解决方案是将所选变量转换为aov()调用之外的因数。
a