Reputation: 727
I am trying to make a Shiny app that outputs an ANOVA table based on a dynamic numeric variable input from the iris
dataset.
This is the part where I am struggling:
aov.model <- aov(input$varNames ~ iris$Species, data = iris)
The above works if I replace the dynamic input part to any of the specified variable names:
aov.model <- aov(Sepal.Length ~ Species, data = iris)
How should I deal with the dynamic input part input$varNames
?
Here is the fully working code:
ui <- fluidPage(
tabsetPanel(
tabPanel("ANOVA",
uiOutput("varNames"),
verbatimTextOutput("anovaTable")
)
)
)
# @
server <- function(input, output) {
output$varNames <- renderUI({
selectizeInput("varNames2",
"Variables: ",
choices = names(iris[, -5])
)
})
output$anovaTable <- renderPrint({
aov.model <- aov(input$varNames ~ iris$Species, data = iris) # Stuck here
print(aov.model)
br()
br()
print(summary(aov.model))
cat("Coefficients"); cat("\n")
print(aov.model$coefficients)
})
}
shinyApp(ui, server)
Upvotes: 0
Views: 672
Reputation: 21349
You do not have varNames
. It should be input$varNames2
. Also, you should call it as
aov.model <- aov(iris[[input$varNames2]] ~ iris$Species, data = iris)
Then you get the following output:
Upvotes: 1