title: Create grouped pie chart from user input R Shiny
body: <p>I want the user to be able to upload a .csv and be able to create a pie chart of it. If there is a column that contains a category they want grouped together they should be able to.
  The following code shows what I want to do, but only works if I know the column name (in this case Gender) when writing the program.</p>
  
  <pre><code>piePlotData = aggregate(. ~ Gender, inFile, sum)
  pie(piePlotData[[input$pieData]], labels = piePlotData[[input$pieGroups]])
  </code></pre>
  
  <p>If possible I would want to replace Gender with <code>input$pieGroups</code></p>
  
  <p>Here is a simple example of data which could be uploaded:</p>
  
  <pre><code>  Gender    Name    Maths   English 
     M        Bob      4        2 
     M        Fred     1        7
     F        Mary     5        4
  </code></pre>
  
  <p>I apologise if this has been answered before, I have tried other people's solutions but I could not get them to work when the data uploaded could be in any format and still keeping the same column names.</p>
  
  <p>I'd prefer if the solution only used the base R package, but any solutions are better than none :P
  Thanks in advance</p>
  
  <p>(Somewhat) Simple code example:</p>
  
  <p>server.R:</p>
  
  <pre><code>library(shiny)
  
  shinyServer(function(input, output, session) {
    inFile = reactive({ return (read.csv(file.choose(), header = TRUE))})
  
    observe({
      updateSelectInput(session, "pieData", choices = names(inFile()))
      updateSelectInput(session, "pieGroups", choices = names(inFile()))
    })
  
    output$plot = renderPlot({
      piePlotData = aggregate(. ~ Gender, inFile, sum)
      pie(piePlotData[[input$pieData]], labels = piePlotData[[input$pieGroups]])
    })
  })
  </code></pre>
  
  <p>ui.R:</p>
  
  <pre><code>shinyUI(pageWithSidebar(
    headerPanel("Grouped Pie Chart"),
    sidebarPanel(
      selectInput("pieData", "Columns in pie", "Update"),
      selectInput("pieGroups", "Groups for pie", "Update")
    ),
    mainPanel(
      plotOutput("plot")
    )
  ))
  </code></pre>