render does not work from shiny but works from R console for PDF

Hello!

I have a toy app that creates an Rmarkdown file and renders it. However, the rendering for the PDF file does not work. Here is the code:

tyui <- fluidPage(
  textInput("stuff1","Enter file name prefix:"),
  downloadButton("report", "Generate report")
)

server <- function(input, output, session) {
	  
  output$report <- downloadHandler(

  
       filename = function() {
    paste(input$stuff1,".pdf",sep="")
    },


    content = function(file) {

      
      id <- showNotification(
        "Rendering report...", 
        duration = NULL, 
        closeButton = FALSE
      )
      on.exit(removeNotification(id), add = TRUE)

fulfilR <-  "buzz1.Rmd"
fulfilW <-     paste(input$stuff1,".pdf",sep="")
 head1 <- paste("title: Test for PDF")
#cont4a <- c("Contact me [via email]{mailto:erinm.hodgess@gmail.com) or use [thi#s link](https://www.erinm1960.shinyapps.io/linreg1)")

cont5 <- "more stuff"


 ap1 <- ifelse(file.exists(fulfilR),"FALSE","TRUE")
 write('---',file=fulfilR,append=ap1)
 write(head1,file=fulfilR,append=TRUE)
  write('---',file=fulfilR,append=TRUE)
 write(cont5,file=fulfilR,append=TRUE)
 write('---',file=fulfilR,append=TRUE)
 print("init1")
 print(file)
 print(fulfilR)
 options(tinytex.verbose=TRUE)
 
      rmarkdown::render(fulfilR,
      c("pdf_document"),
        output_file = file,
      envir = new.env(parent = globalenv())
      )
      print("endtest")
    }
  )
}

shinyApp(ui,server)

Here is the output from the console:

[1] "init1"
[1] "C:\\Users\\ERIN~1.HOD\\AppData\\Local\\Temp\\RtmpMtQbME\\file4fc06bae49ee.pdf"
[1] "buzz1.Rmd"
Warning in has_crop_tools() :
  
Tool(s) not installed or not in PATH: ghostcript
-> As a result, figure cropping will be disabled.


processing file: buzz1.Rmd

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......................................................................| 100%
  ordinary text without R code


output file: buzz1.knit.md

"C:/Users/ERIN~1.HOD/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS buzz1.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc4fc043d2f49.tex --lua-filter "C:\Users\ERIN~1.HOD\ONEDRI~1\MYDOCU~1\R\WIN-LI~1\4.0\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\Users\ERIN~1.HOD\ONEDRI~1\MYDOCU~1\R\WIN-LI~1\4.0\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in" 
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021/W32TeX) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
Warning: Error in : LaTeX failed to compile C:\Users\ERIN~1.HOD\AppData\Local\Temp\RtmpMtQbME\file4fc06bae49ee.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
  [No stack trace available]

However, when I run the render on the generated file from the command line, it works fine.

I'm guessing that it has something to do with how Shiny sees the file.

Any help much appreciated.
Sincerely,
Erin

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.