0

I'm working on R Sweave to generate a report in PDF in a shiny application on a server. Everything works perfectly in my computer, locally, I can generate my PDF in the application. It also works in the server. But, when I wanted to add an image in a background, a rectangular header, in the R Sweave , it didn't work anymore on the server, it can't be generated.

Here's the code I added in my R Sweave, so my report :

\usepackage{background}
\usepackage{graphicx}

\backgroundsetup{
   scale=0.5,
   angle=0,
   opacity=1,
   color=black,
   contents={\begin{tikzpicture}[remember picture, overlay]
      \node at ([yshift=-.6in] current page.north)
            {\includegraphics[width = \paperwidth]{myheader}};
     \end{tikzpicture}}
 }

Did I forget something ?

Thank you

EDIT : After some researches, I think I probably have a problem with these functions in the script server.R :

output$report <- downloadHandler(

  filename = function(){name()},
  content = function(file) {
    out = knitr::knit2pdf(input="my_report.Rnw",encoding = "UTF-8",clean=TRUE)
    file.rename(out, file)
    file.copy(file,paste0("export/",Sys.Date(),"_",name()))
  },

  contentType = 'application/pdf'
)

It seems that I probably forgot an argument in my function out = knitr::knit2pdf(input="my_report.Rnw",encoding = "UTF-8",clean=TRUE). It seems that it can only manage a text on UTF-8 and geometric forms, not an image.

Alice
  • 54
  • 6
  • We'd need the error message you see. Also first things first: some servers simply do _not_ have a full texlive installation. – Dirk Eddelbuettel Jan 06 '20 at 14:35
  • It displays: "File not found, Firefox cannot find the file at the address http://...." – Alice Jan 07 '20 at 09:05
  • 1
    And just to cover the obvious: you reference a file `myheader`. Do you have such a file in the current directory? – Dirk Eddelbuettel Jan 07 '20 at 12:40
  • Yes, there's an image, there's no problem at this point. – Alice Jan 07 '20 at 14:29
  • I just add a new part on the topic. – Alice Jan 07 '20 at 14:38
  • 1
    I do not understand what you are trying to say with "there is an image". You tell latex that a file `myheader` (no extension) is to to included. You must then supply such a file. Lastly, you have a 10-line segment there that breaks. Maybe debug it to a 3 line segment (ie just `\includegraphics` first, then tikz and so on. This is why we usually ask for [minimally complete verifiable examples](https://stackoverflow.com/help/minimal-reproducible-example) which your question did not supply. – Dirk Eddelbuettel Jan 07 '20 at 14:39
  • 1
    Sorry, I answered quickly and I didn't detail enough. The code in the 1st part of the topic is in my R Sweave, so the report I want to generate. I want to generate it through a Shiny app, which is the 2nd part of code (in the EDIT). My report generate perfectly apart from the Shiny app (if I execute it locally). It won't generate through the Shiny app and I think it's because of this function "knitr::knit2pdf(input="my_report.Rnw",encoding = "UTF-8",clean=TRUE)". – Alice Jan 07 '20 at 16:08

1 Answers1

1

Problem solved! In my R Sweave, I just added \usepackage{tikz} and it works!

Thanks to Dirk Eddelbuettel for his help.

Alice
  • 54
  • 6