title: Generate report with Shiny app and Rmarkdown
body: <p>I would like to create a shiny app that allows you to download a report. Right now I'm trying to keep things super simple and the only input on the shiny app is some text that the user can input using <code>textarea</code>:</p>
  
  <pre><code>library(shiny)
  server &lt;- function(input, output) {
    output$downloadReport &lt;- downloadHandler(
      filename = function() {
        paste('my-report', sep = '.', switch(
          input$format, PDF = 'pdf', HTML = 'html', Word = 'docx'
        ))
      },
      content = function(file) {
        src &lt;- normalizePath('report.Rmd')
  
        # temporarily switch to the temp dir, in case you do not have write
        # permission to the current working directory
        owd &lt;- setwd(tempdir())
        on.exit(setwd(owd))
        file.copy(src, 'report.Rmd', overwrite = TRUE)
  
        library(rmarkdown)
        out &lt;- render('report.Rmd', switch(
          input$format,
          PDF = pdf_document(), HTML = html_document(), Word = word_document()
        ))
        file.rename(out, file)
      }
    )
  }
  
  ui &lt;- fluidPage(
    tags$textarea(id="text", rows=10, cols=80, "Default value"),
  
    flowLayout(radioButtons('format', 'Document format', c('HTML', 'Word'),
                            inline = TRUE),
               downloadButton('downloadReport'))
  
  )
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>My <code>report.Rmd</code> file only has two lines:</p>
  
  <pre><code># Title
  
  `r renderPrint({ input$text })`
  </code></pre>
  
  <p>Alas, the report is not printing <code>input$text</code>.</p>