title: R Shiny - Generating PDF report
body: <p>I need to generate and download a PDF report from a shiny app. I've found this (I've placed the app.R and report.Rmd files in the same folder):</p>
  
  <p><a href="https://shiny.rstudio.com/articles/generating-reports.html" rel="nofollow noreferrer">https://shiny.rstudio.com/articles/generating-reports.html</a></p>
  
  <pre><code>shinyApp(
  ui = fluidPage(
  sliderInput("slider", "Slider", 1, 100, 50),
  downloadButton("report", "Generate report")
  ),
  server = function(input, output) {
  output$report &lt;- downloadHandler(
    # For PDF output, change this to "report.pdf"
    filename = "report.html",
    content = function(file) {
      # Copy the report file to a temporary directory before processing it, in
      # case we don't have write permissions to the current working dir (which
      # can happen when deployed).
      tempReport &lt;- file.path(tempdir(), "report.Rmd")
      file.copy("report.Rmd", tempReport, overwrite = TRUE)
  
      # Set up parameters to pass to Rmd document
      params &lt;- list(n = input$slider)
  
      # Knit the document, passing in the `params` list, and eval it in a
      # child of the global environment (this isolates the code in the document
      # from the code in this app).
      rmarkdown::render(tempReport, output_file = file,
        params = params,
        envir = new.env(parent = globalenv())
      )
    }
  )
  }
  )
  
  report.Rmd:
  
  ---
  title: "Dynamic report"
  output: html_document
  params:
  n: NA
  ---
  
  ```{r}
  # The `params` object is available in the document.
  params$n
  ```
  
  A plot of `params$n` random points.
  </code></pre>
  
  <p>The problem is, when I run it and press download, I get the following error:</p>
  
  <pre><code>Warning in normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="C:\Users\*\AppData\Local\Temp\Rtmp0SaXzj\report.Rmd": Das      System kann die angegebene Datei nicht finden
  Warning: Error in tools::file_path_as_absolute: file 'C:\Users\*\AppData\Local\Temp\Rtmp0SaXzj\report.Rmd' does not exist
  Stack trace (innermost first):
  57: tools::file_path_as_absolute
  56: dirname
  55: setwd
  54: rmarkdown::render
  53: download$func [#255]
   4: &lt;Anonymous&gt;
   3: do.call
   2: print.shiny.appobj
   1: &lt;Promise&gt;
  Error : file 'C:\Users\*\AppData\Local\Temp\Rtmp0SaXzj\report.Rmd' does not exist
  </code></pre>
  
  <p>After a bit of checking I've seen that the copy step does not work, with the error:</p>
  
  <pre><code>file.copy("report.Rmd", "/test/report.Rmd")
  &gt;FALSE
  </code></pre>
  
  <p>On one hand I think the problem is I am not in the correct folder, and on the other that I can't access the tempDir.</p>
  
  <p>Any ideas?</p>