Error calculating mean by input variable in Shiny
Using the mtcars dataset in R, I am tying to use the input variable (cyl, am etc...) to calculate the mean mpg by that variable.
My code in the ui.R is like:
verbatimTextOutput("Avg_Mileage")
My code in the shinServer function in server.R is like:
carsdata <- mtcars
output$Avg_Mileage <- renderPrint({aggregate(mpg~input$variable, carsdata,mean)})
I have tried to change the code in server.R in various ways. But I keep getting the message about conflicting variable lengths: "variable lengths differ (found for 'input$variable') "
I would appreciate any help in trying to see how can this mean mpg by input variable be implemented in Shiny
I managed to figure out this one.
Changed the server.R to:
output$Avg_Mileage <- renderTable({aggregate(as.formula(formulaText()), carsdata,mean)})
and ui.R to:
tableOutput(outputId = "Avg_Mileage")
链接地址: http://www.djcxy.com/p/24842.html
上一篇: 计算计算值的平均值