A. Thibault
A. Thibault

Reputation: 21

Generate report from shiny app with markdown : file not found

I want to generate a pdf report from my shiny app on shiny server. It work well on my computer. I try to put in on my shiny server, but when i want to generate the report, I get a firefox "file not found" page instead of getting the pdf.

I use the code shown at : https://shiny.rstudio.com/articles/generating-reports.html I also try to use directly my .Rmd file instead of copy/paste it to the temp dir, but I got the same error.

My server file :

output$pdfGen <- downloadHandler(
    # For PDF output, change this to "report.pdf"
    filename = "rapport_preci.pdf",
    content = function(file) {
      withProgress(message = "Génération du pdf en cours", value = 0,{
        src <- normalizePath('report.Rmd')

        # temporarily switch to the temp dir, in case you do not have write
        # permission to the current working directory
        owd <- setwd(tempdir())
        on.exit(setwd(owd))
        file.copy(src, 'report.Rmd', overwrite = TRUE)

      # Set up parameters to pass to Rmd document
      params <- list(varSite = input$pdfSite,
                     ...
                     varTrans= input$valTrans1
                     )

      # 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).
      out <- render("report.Rmd", output_file = file,
                        params = params,
                        encoding = "UTF-8"
      )
      file.rename(out, file)
      })
    }
  )

I think my app does not found my .Rmd file, but how do I fix that ? All my files are in the same folder.

Upvotes: 0

Views: 1229

Answers (1)

nidabdella
nidabdella

Reputation: 821

I just run part of the code, and apparently the problem is when you set owd <- setwd(tempdir()) Here is what that does:

> tempdir()
[1] "/tmp/RtmpKafhlt"
> owd = setwd(tempdir())
> owd
[1] "/home/med"

and you probably don't have access to the home dir of the host server. You need to set replace on.exit(setwd(owd)) with on.exit(owd)

Upvotes: 0

Related Questions