0

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

Josh
  • 1,237
  • 4
  • 15
  • 22
  • Essentially I'd like to be able to group my data by any combination of the 7 above variables. – Josh Jun 16 '16 at 00:29
  • ggplot(groups%>% group_by(input$groupvars[1...., Where is groups defined? it is not in the function. You should really build this code step-by-step as opposed to trying fit everything into one line of code. Bye the way, without a brief bit of sample data, this problem will not get much attention. – Dave2e Jun 16 '16 at 00:44

0 Answers0