Hi Friends,
Based on grouping variable selection by user want data to be aggregated. There are 5 variables any combination of that can be used for grouping. Below is simplified version with 2 grouping variables.
The below code works but need to work for varying inputs (Grouping Variable) as per user
Can you please suggest if this can be done with the base R aggregate or there is some other way to do it.
library(shiny)
m1<-rnorm(20,100,sd=20)
m2<-rnorm(20,120,sd=40)
m3<-rnorm(20,140,sd=60)
g1<-rep(c("a","b"),10)
g2<-rep(c("c","d","e","f"),5)
data<-data.frame(m1,m2,m3,g1,g2)
ui<-fluidPage(
selectInput("Grp","Grp",choices=c("g1","g2"),multiple=TRUE),
textOutput("text1"),
tableOutput("agg_table")
)
server<-function(input,output,session)
{
output$text1<-renderText({input$Grp[1]})
grp_data <- reactive({
aggregate(data[,1:3],by=list(data[[input$Grp[1]]],data[[input$Grp[2]]]),sum)
})
output$agg_table <-renderTable( grp_data())
}
shinyApp(ui=ui,server=server)
```r