title: R Shiny: read data file, get user to select variable, plot with ggplot
body: <p>As stated in the title, I'm trying to use Shiny in R to create a program that reads a csv file uploaded by the user, after which the user can select a variable from that file to view a plot that is plotted by ggplot. I'm trying to achieve this over two tabs, the first tab will read the file and the second tab will get the user to select the variable to view the plot. </p>
  
  <p>My codes are as below. Currently, I am able to successfully read the user's file but I am not able to plot based on the variable selected (I currently only have 1 variable "Location" for demo). (HomeWTaxAmt is the y variable to plot against).</p>
  
  <pre><code>library(shiny)
  library(ggplot2)
  library(data.table)
  library(RColorBrewer)
  options(scipen=1000)
  
  ui &lt;- fluidPage(
    navbarPage("User Interface:",tabPanel("Upload",
    titlePanel("Uploading Files"),
    sidebarLayout(
      sidebarPanel(
        fileInput("file1", "Choose CSV File",
                  multiple = TRUE,
                  accept = c("text/csv",
                             "text/comma-separated-values,text/plain",
                             ".csv")),
        tags$hr(),
        checkboxInput("header", "Header", TRUE),
        radioButtons("sep", "Separator",
                     choices = c(Comma = ",",
                                 Semicolon = ";",
                                 Tab = "\t"),
                     selected = ","),
        tags$hr(),
        radioButtons("disp", "Display",
                     choices = c(Head = "head",
                                 All = "all"),
                     selected = "head"),
        radioButtons("quote", "Quote",
                     choices = c(None = "",
                                 "Double Quote" = '"',
                                 "Single Quote" = "'"),
                     selected = '"')),
      mainPanel(
        verbatimTextOutput("summary"),
        tableOutput("contents")
      ))), 
    tabPanel("Graphing",
                   titlePanel("Plotting Graphs"),
                   sidebarLayout(
                     sidebarPanel(
                       selectInput("variable", "Variable:",
                                   list("Location"))),
                     mainPanel(
                       h3(textOutput("caption")),
                       plotOutput("ggplot")
                     )
    ))
  ))
  
  server &lt;- function(input, output) {
    output$contents &lt;- renderTable({
      req(input$file1)
      library(data.table)
      data &lt;- fread(input$file1$datapath,
                    header = input$header,
                    sep = input$sep,
                    quote = input$quote)
  
      if(input$disp == "head") {
        return(head(data))
      }
      else {
        return(data)
      }
  
    })
    output$summary &lt;- renderPrint({
      summary(data)
    })
  
    formulaText &lt;- reactive(function() {
      paste("HomeWTaxAmt ~", input$variable)
    })
  
    output$caption &lt;- renderText(function() {
      formulaText()
    })
  
    output$ggplot &lt;- renderPlot(function() {
      data &lt;- fread(input$file1$datapath,
                    header = input$header,
                    sep = input$sep,
                    quote = input$quote)
      if(is.null(data)) return(NULL)
      # check for the input variable
      ggplot(data, aes(x=reorder(factor(data[input$variable]), -abs(HomeWTaxAmt), function(x){sum(x)}), 
                       weight = abs(HomeWTaxAmt), fill = factor(data[input$variable]))) + geom_bar(show.legend=FALSE) + xlab(input$variable) + 
              scale_fill_manual(values=brewer.pal(n = 12, name = "Paired"))
    })
  }
  
  shinyApp(ui, server)
  </code></pre>