Sweave, Shiny: 无法在服务器上生成 PDF。

huangapple go评论74阅读模式
英文:

Sweave, Shiny : can't generate a PDF on the server

问题

我正在使用R Sweave在服务器上的shiny应用程序中生成PDF报告。在我的计算机上,一切都正常,我可以在应用程序中生成PDF。它也在服务器上运行正常。但是,当我想在R Sweave中添加一个背景图像,一个矩形标题时,它在服务器上不再工作,无法生成。

这是我在我的R Sweave报告中添加的代码:

\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}}
 }

我是否忘记了什么?

谢谢

编辑:经过一些研究,我认为我在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'
)

似乎我可能在我的函数out = knitr::knit2pdf(input="my_report.Rnw",encoding = "UTF-8",clean=TRUE)中忘记了一个参数。似乎它只能处理UTF-8编码的文本和几何形状,而不能处理图像。

英文:

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.

答案1

得分: 1

问题解决了!在我的R Sweave中,我只是添加了\usepackage{tikz},然后它就可以工作了!感谢Dirk Eddelbuettel的帮助。

英文:

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

Thanks to Dirk Eddelbuettel for his help.

huangapple
  • 本文由 发表于 2020年1月6日 22:31:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613866.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定