How to pass data from one `reactive()` to another in R shiny?
<p>A shiny app that takes in user input and sends the column names to <code>selectizeInput()</code> box. The user then selects few column names and a subset of the data is to be created in another part/tab in the same app.</p>

<p>The app's UI has the following parts :</p>

<ol>
<li>Navbar</li>
<li>One tab of the nav bar to select data and columns</li>
<li>Other tab to create a subset of the data and plot.</li>
</ol>

<p><em>ui.R</em></p>

<pre><code> library(markdown)
require(XLConnect)


shinyUI(fluidPage(
  # Application title
  img(class = "img-polaroid",
      src = paste0(
      "http://www.aithent.com/wp-content/uploads/2015/05/aithent-website-200x80.png"
    )
  ),
  navbarPage(
    "Project Vanguard",
    tabPanel(
      "Table",
      titlePanel("Select Data"),
      sidebarLayout(
        sidebarPanel(
          selectInput(
            "fileType",
            "Select File Type:",
            c("MS Excel Worksheet (xls,xlsx)" = "xls",
              "Text/CSV (.csv)" = "csv")
          ),
          fileInput(
            'file1',
            'Choose file to upload',
            accept = c(
              'text/csv',
              'text/comma-separated-values',
              'text/tab-separated-values',
              'text/plain',
              '.csv',
              '.tsv',
              'application/vnd.ms-excel',
              'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
              '.xlsx',
              '.xls'
            )
          ),
          tags$hr(),
          checkboxInput('header', 'Header', TRUE),
          radioButtons('sep', 'Separator',
                       c(Comma = ',',
                         Semicolon = ';',
                         Tab = '\t'
                       ),','),
          radioButtons(
            'quote',
            'Quote',
            c(None = '',
              'Double Quote' = '"',
              'Single Quote' = "'"
              ),'"'
          ),
          tags$hr(),
          uiOutput("selector1"),
          uiOutput("selector2")
          ),
        mainPanel(dataTableOutput('table'))
      )),
    tabPanel("Plot",
             sidebarLayout(
               sidebarPanel(radioButtons(
                 "plotType", "Plot type",
                 c("Scatter" = "p", "Line" = "l"))),
               mainPanel(dataTableOutput("ResultTab"),
                         plotOutput("plot")))),
    navbarMenu("More",
               tabPanel(
                 "Summary",
                 verbatimTextOutput("summary"))))
))
</code></pre>

<hr>

<p><em>server.R</em>  </p>

<pre><code>library(sqldf)
options(scipen = 999)
shinyServer(function(input, output, session){
  output$plot &lt;- renderPlot({
    plot(data$Count, data$Sales, type = input$plotType)
  })
  output$summary &lt;- renderPrint({
    summary(data)
  })
  data &lt;- reactive({
    inFile &lt;- input$file1
    if (is.null(inFile))
      return(NULL)
    if (input$fileType == 'csv') {
      table1 &lt;- read.csv(
        inFile$datapath,
        header = input$header,
        sep = input$sep,
        quote = input$quote
      )
      return(table1)
    } else if (input$fileType == 'xls') {
      table1 &lt;- readWorksheetFromFile(inFile$datapath, sheet = 1)
    }
  })

  output$table &lt;- renderDataTable({
    data()
  })

  output$selector1 &lt;- renderUI({
    selectizeInput("GroupVar",
                   "Choose Group Variables:",
                   as.list(colnames(data())),
                   multiple = TRUE)
  })
  output$selector2 &lt;- renderUI({
    selectizeInput("AnalysisVar",
                   "Choose Analysis Variables:",
                   as.list(colnames(data())),
                   multiple = TRUE)
  })

  ResultSet &lt;- reactive({
    Src &lt;- data()
    GVars &lt;- as.character(input$selector1)
    Avars &lt;- as.character(input$selector2)
    gvs &lt;- paste(unlist(strsplit(GVars, ' ')), collapse = ",")
    avs &lt;-
      paste0('sum(',
             strsplit(Avars, ' '),
             ') as SumOf',
             strsplit(Avars, ' '),
             collapse = ",")
    sqlStat &lt;-
      paste0("SELECT ", gvs, ',', avs, " FROM Src GROUP BY ", gvs)
    Result &lt;- sqldf(sqlStat)
    return(Result)
  })
  output$ResultTab &lt;- renderDataTable({
    ResultSet()
  })
})
</code></pre>

<p>In the code, I'm getting the following error :</p>

<p><code>Error in sqliteSendQuery(con, statement, bind.data) : 
  error in statement: near ",": syntax error</code></p>

<p>I wish to know two things  Is my error in SQL because of :
1.Improper data passing, i.e., incorrect usage in reactive <code>ResultSet</code> by <code>Src&lt;-data()</code>?
or
2. Improper reference and usage of <code>selectizeInput()</code> by the statement <code>GVars &lt;- as.character(input$selector1)</code>?</p>