Wednesday, November 28, 2018

r - 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

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...