Downloading parameterized rmd using shinyR normalizePath error

I am using the shiny app:

setwd("XXXXX")
library(shiny)
library(markdown)

 ui = fluidPage(
    textInput("year", "Enter Year"),
    downloadButton("report", "Generate report")
  )
  server = function(input, output) {
    output$report <- downloadHandler(

      filename = "report.html",
      content = function(file) {

        dir.exists
        tempReport <- file.path(tempdir(), "report.Rmd")
        file.copy("report.Rmd", tempReport, overwrite = TRUE)
        
        params <- list(year = input$year)
        
        rmarkdown::render(tempReport, output_file = file,
                          params = params,
                          envir = new.env(parent = globalenv())
        )
      }
    )
  }
  
shinyApp(ui, server)

The working directory is set as where i have the report.rmd file and the app.R file. When i run the app and enter the year, click generate report i get this error in the console:

Warning in normalizePath(path.expand(path), winslash, mustWork) : path[1]="C:\Users\JL16\AppData\Local\Temp\Rtmpe6ovSc/report.Rmd": The system cannot find the file specified Warning: Error in abs_path: The file 'C:\Users\JL16\AppData\Local\Temp\Rtmpe6ovSc/report.Rmd' does not exist. [No stack trace available]

For reference this is the Rmd

---
output:
  html_document: default
params:
  trip:
    label: "Enter Trip Code"
    value: BM519BT
  year:
    label: "Choose Year"
    value: 2019
title: "Report"
date: "`r format(Sys.time(), '%d %B %Y')`"
---

```{r}

library(knitr)
library(rmarkdown)
#select the years to work on
YEAR<-params$year
YEAR

#SELECT THE TRIP

TripID <- params$trip
TripID

I think the code in the app is fine its just getting it to link to the rmd file that i am having issues with.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.