2

Building on this previous issue: https://github.com/rstudio/rmarkdown/issues/1285

Trying to download into HTML (or PDF) from a Shiny app using rmarkdown. But error message:

Error in tools::file_path_as_absolute: file '/tmp/RtmpCjHU3c/report.Rmd' does not exist

Using the generic example produces the error:

ui <- fluidPage(

sliderInput("slider", "Slider", 1, 100, 50),
downloadButton("report", "Generate report")
)

server <- function(input,output) {

output$report <- downloadHandler(

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

tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)

params <- list(n = input$slider)

rmarkdown::render(tempReport, output_file = file,
                    params = params,
                    envir = new.env(parent = globalenv())
  )})}

  shinyApp(ui = ui, server = server) 

I have installed tinytex version 0.5 and rmarkdown version 1.8, as per:

Knitr wont compile PDF: "Error in tools::file_path_as_absolute(output_file)"

I am running Ubuntu 16.04.4 on Amazon AWS.

For what it's worth, I am using TeX Live and knitr works fine to generate PDFs from within a standard rmarkdown document.

I tried the following as well:

tinytex::install_tinytex()

Which produced the following error:

Error: Detected an existing tlmgr at /usr/bin/tlmgr. It seems TeX Live has been installed (check tinytex:::texlive_root()). You have to uninstall it, or use install_tinytex(force = TRUE) if you are sure TinyTeX can override it (e.g., you are a PATH expert or installed TinyTeX previously).

Despite not being a PATH expert, I forced install, which produced:

Error in root_dir(normalizePath(path), "..", "..", "..") : /usr/share/texlive does not seem to be the root directory of TeXLive (no "bin/" dir under it)

Going to try this patch next:

https://github.com/yihui/tinytex/blob/master/R/install.R

Hopefully it works for Linux.

Any suggestions would be helpful!

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • 1
    Do you have a file named `report.Rmd` in the same directory as your shiny app? I get the same error message without the file present. With such a file, your app works fine. BTW, you should decide whether you want TexLive or TinyTeX and install only one of them. – Ralf Stubner May 31 '18 at 11:59
  • @ Ralf Stubner: No `report.Rmd` file was present. I then created one, with the same error message produced. I created a new Ubuntu instance with only TinyTex installed, same error message, and `knit2pdf` no longer worked in vanilla `.Rmd` file, as it called for TextLive to be installed. Some directory issue here, thinking now about a difference in `Shiny` server.R or ui.R files.... – bankhedge12 May 31 '18 at 14:07
  • Just tried to read a basic .txt file in R and failed with "Error in file(file, "rt") : cannot open the connection.....No such file or directory". Issue likely around here... – bankhedge12 Jun 01 '18 at 05:02
  • What is the output of `getwd()` before you try to read the file? Is the file in that directory? You can check with `list.files(".")`. – Ralf Stubner Jun 01 '18 at 08:42

0 Answers0