I used to be able to include images from URLs in PDF reports generated from shiny apps doing ![](url.com)
. A few markdown versions later I get the following error: ! 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", "."]
to the YAML
downloads the imaged file locally but only works in local r-markdown
files.
extract-media
workaround to function?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
![click](https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1)
## 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)
}
)
The latest version of rmarkdown requires images to be downloaded locally. Adding pandoc_args: ["--extract-media","."]
to the YAML header works for local rmarkdown files but not in a shiny app environment.
Downgrading rmarkdown below version 1.9 will enable images to be automatically downloaded.
Alternatively, files can be downloaded locally using download.file()
and reference with an absolute path.
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
download.file(url = "https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1"), destfile = "stack-overflow.png")
![click]("stack-overflow.png")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With