I'm making a shiny app with the goal of allowing users to group population data based on up to 7 variables. The relevant ui code chunk is:
checkboxGroupInput("groupvars",
label = h3("Variable Options"),
choices = c('Education' = 1,
'Gender' = 2,
'HH.Income'=3,
'Marital.Status'=4,
'Party.Reg' = 5,
'Race'=6,
'State'=7),
selected = c(1,2,3,4,5,6,7)),
My desired output here is a checkbox input where users can break down the overall population into subgroups based on the above variables.
On the server side, I'm struggling with how to put the input$groupvars into a df%>%groupby(___). My attempt was:
server <- function(input, output){
output$local <- renderPlot(
ggplot(groups%>%
group_by(input$groupvars[1], input$groupvars[2], input$groupvars[3],
input$groupvars[4], input$groupvars[5], input$groupvars[6],
input$groupvars[7])%>%
summarise(size = sum(total),
locAgg = sum(loc),
demAgg = sum(dem))%>%
mutate(turnout = locAgg/size,
pctDem = demAgg/size),
aes(y = pctDem, x = turnout, color = input$color, size = size))+
geom_point()
)
}
The problem is that my code seems to be just not be grouping at all and returns a scatter plot with just one point. I can't really put a sample of the data online but let me know if there is something else I can do to make the question more clear I'm happy to try.
Hope one of you can help! Thanks in advance