title: Downloading Reactive Objects in Shiny
body: <p>Is it possible to download objects in shiny without having to create a separate, redundant, instance of that object within the <code>downloadHandler()</code> call? For example, consider the following example:</p>
  
  <p>ui.R</p>
  
  <pre><code>library(shiny)
  
  shinyUI(pageWithSidebar(
    headerPanel("Simple Example"),
  
    sidebarPanel(
      textInput("options","Enter some content:",""),
      submitButton("Go")
    ),
  
    mainPanel(
      tableOutput("dataTable"),
      downloadButton('downloadData','Save Data as CSV File')
    )
  ))
  </code></pre>
  
  <p>server.R</p>
  
  <pre><code>library(shiny)
  
  shinyServer(function(input, output) {
    makeQuery &lt;- reactive({
        if(input$options == ""){
          return("Enter some options")
        }
        else {
          return(input$options)
        }
    })
  
    runQuery &lt;- function(query){
      dat &lt;- data.frame(v1=rep(query,5))
      return(dat)
    }
  
    output$dataTable &lt;- renderTable({
      query &lt;- makeQuery()
      if(grepl("^Enter",query)){
        return(data.frame(Error=query))
      } else {
        return(runQuery(query))
      }
    },include.rownames=FALSE)
  
    output$downloadData &lt;- downloadHandler(
      filename = c('data.csv'),
      content = function(file) {
        write.csv(runQuery(makeQuery()), file)
      }
    )
  
  })
  </code></pre>
  
  <p>The issue I have with the above example is that I am running <code>runQuery()</code> within both the <code>renderTable()</code> and <code>downloadHandler()</code> calls. In this example there isn't really any extra overhead but in my real example this requires running a 5-10 minute process so it is extremely inefficient to call it twice whenever someone downloads the data. </p>
  
  <p>Is there anyway that I can get around this issue by referencing an already created object in the <code>downloadHandler()</code> call or some other work around?</p>