【发布时间】:2019-03-10 05:06:11
【问题描述】:
我曾经能够在 PDF 报告中包含来自 URL 的图像,该报告是由执行  的闪亮应用程序生成的。几个降价版本之后我收到以下错误:! Unable to load picture or PDF file https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1 for the same code。
Adding pandoc_args: ["--extract-media", "."] 到 YAML 在本地下载映像文件,但仅适用于本地 r-markdown 文件。
- shinyapp 如何存储本地文件以及如何使
extract-media变通方法发挥作用? - 如何在 shinyapps 的 PDF 中包含 Web 图像?
r-markdown 示例
title: "Test"
header-includes:
- \usepackage{graphicx}
- \usepackage{hyperref}
output:
pdf_document:
latex_engine: xelatex
pandoc_args: ["--extract-media","."]
number_sections: yes
keep_tex: yes
classoption: article
papersize: A4
fontsize: 10pt
geometry: margin=0.9in
linestretch: 1.15
---
## R Markdown

server.R 块触发报告生成
## img report
output$downloadImgReport <- downloadHandler(
filename = function() {
paste0(format(Sys.time(), '%Y%m%d'),'-WS-CM-image-report-',docounts()$count, '.pdf')
},
content = function(file) {
src <- normalizePath('Untitled.Rmd')
src1 <- normalizePath('logo.png')
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'Untitled.Rmd', overwrite = TRUE)
file.copy(src1,'logo.png')
library(rmarkdown)
out <- render('Untitled.Rmd', output_format=pdf_document(latex_engine = "xelatex"))
writetolog(1,session$token)
file.rename(out, file)
}
)
【问题讨论】:
-
错误似乎来自XeLaTeX,也许尝试更新它?不过,至少以下内容对我有用:
echo '' | pandoc --pdf-engine=xelatex -o foo.pdf -
我更新了包括 Latex 在内的所有软件包,但没有成功。
-
但是直接调用 pandoc 有效吗?就像我在上面发布的那样?
-
使用最新版本的 rmarkdown,您必须下载此类图像(例如通过
download.file())并在生成 PDF 时使用本地图像路径。 -
我确信 1.8 会做到这一点。 1.9 可能会这样做,但我不完全确定(需要检查 git 日志)。
标签: r shiny latex r-markdown pandoc