title: How to save (not upload) a file created from a Shiny interface?
body: <p>I have asked this question on the Shiny Google group but once it is published it is immediately deleted, I don't know why.</p>
  
  <p>So I ask this question here.</p>
  
  <p>I know how to upload a file created from a Shiny application but I have unsuccessfully spent a couple of hours to find how to save a file on the hard drive. Please could you show me a way to do so ? For instance I'd like to save a file created with sink() or a RData file.</p>
  
  <p>Below is an (artificial) example of one of my numerous attempts. The sweaveSave() function does not work. Please don't pay attention to the plot, it does not play a role in my question.</p>
  
  <p><strong>server.R</strong></p>
  
  <pre><code>library(shiny)
  ##
  ## function creating a Sweave report 
  ##
  createReport &lt;- function(file){
          sink(file) 
          cat(
  "\\documentclass{article}\n
  \\begin{document}\n
  \\SweaveOpts{concordance=TRUE}
  This is the Rnw file.\n
  &lt;&lt;fig=TRUE&gt;&gt;=
  plot(0,0)
  @\n
  \\end{document}\n") 
          sink()
  }
  
  ##
  ## Shiny server
  ##
  shinyServer(function(input, output) {
      ##
      ## Create plot 
      ##
      createPlot &lt;- reactive({
          # generate an rnorm distribution and plot it
          titl &lt;- paste0("Exponential distribution with rate ", round(input$parameter,2)) 
      curve(dexp(x,rate=input$parameter), from=0, to=5, main=titl, ylab=NA, xlab=NA)
          })
      ##
      ## output : plot
      ##
      output$distPlot &lt;- renderPlot({
          createPlot()
      })
      ##
      ##  output : download Sweave file 
      ##
      output$sweavedownload &lt;-   downloadHandler(
          filename="report00.Rnw",
          content = createReport
      )
      ##
      ## save Sweave file 
      ##
      sweaveSave &lt;-   reactive({
          if(input$save){
                  createReport("REPORT00.Rnw")
          }else{NULL}
      })
  })
  </code></pre>
  
  <p><strong>ui.R</strong></p>
  
  <pre><code>library(shiny)
  shinyUI(pageWithSidebar(
  
    # Application title
    headerPanel("Hello Shiny!"),
  
    # Sidebar panel
    sidebarPanel(
      sliderInput("parameter", 
                  "Rate parameter:", 
                  min = 0.0000000001, 
                  max = 10, 
                  value = 5),
      checkboxInput("save", "Check to save and download")
    ),
  
    # Main panel
    mainPanel(
      plotOutput("distPlot"),
      conditionalPanel(
        condition = "input.save",
        downloadLink("sweavedownload", "Download")
      )
    )
  ))
  </code></pre>