【发布时间】:2017-01-01 00:02:03
【问题描述】:
有 r Shiny 应用程序和 Rmd 文件。尝试使用 downloadHandler() 下载,但收到 Adobe Acrobat 错误提示:
“Acrobat 无法打开 'rstudio-iV1460.pdf',因为它不是受支持的文件类型或文件已损坏(例如,它是作为电子邮件附件发送的并且未正确解码)。 "
发现这是由于使用了 Acrobat v11.0 并且需要确保文档的头部是使用 %PDF 字符串格式化的。
参考:https://helpx.adobe.com/acrobat/kb/pdf-error-1015-11001-update.html
问题:我应该把这个 %PDF 放在哪里,我该如何解决这个问题?我是放在Rmd文档还是tex文档?
这是我在我的 r Shiny 应用程序中从 Rmd 生成 pdf 的方式:
服务器.r
shinyServer(function(input, output) {
# dowload from Rmd file
output$downloadReport <- downloadHandler(
filename = 'input.pdf',
content = function(file) {
src <- normalizePath('input.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, 'input.Rmd')
library(rmarkdown)
out <- render('input.Rmd', pdf_document())
file.rename(out, file)
}
)
}
输入.Rmd
---
always_allow_html: yes
output:
pdf_document:
keep_tex: yes
---
```{r}
test
```
ui.r
fluidPage(
downloadButton('downloadReport')
)
【问题讨论】:
-
您不应该使用
pdf_document()而不是html_document()吗?您是否检查过input.pdf的 内容 在渲染后的样子(例如,使用文本编辑器)? -
是的,我应该使用 pdf_document()。似乎还需要一些额外的 LaTex 包。现在可以了。谢谢。
标签: r pdf shiny r-markdown