rstudio / revealjs

R Markdown Format for reveal.js Presentations
Other
325 stars 86 forks source link

Unable to load image of type pdf #149

Open ssp3nc3r opened 2 years ago

ssp3nc3r commented 2 years ago

An image of type pdf does not display on a slide either when using

knitr::include_graphics()

or markdown,

![]()

Here's an example:

---
title: "Untitled"
output: 
  revealjs::revealjs_presentation: default
---

# Slide with Plot

```{r, echo=FALSE}
pdf("myplot.pdf")
plot(x = 1:10, y = 1:10)
dev.off()

load image using knitr

knitr::include_graphics("myplot.pdf")

load image using markdown


Here's information from `xfun::session_info('revealjs')` my session?

R version 4.1.2 (2021-11-01) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.1, RStudio 2021.9.1.372

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version: base64enc_0.1.3 digest_0.6.29 evaluate_0.14 fastmap_1.1.0 glue_1.6.0
graphics_4.1.2 grDevices_4.1.2 highr_0.9 htmltools_0.5.2 jquerylib_0.1.4
jsonlite_1.7.2 knitr_1.37 magrittr_2.0.1 methods_4.1.2 revealjs_0.9.1.9007 rlang_0.4.12 rmarkdown_2.11 stats_4.1.2 stringi_1.7.6 stringr_1.4.0
tinytex_0.36 tools_4.1.2 utils_4.1.2 xfun_0.29 yaml_2.2.1



I've upgraded all packages and tested the issue on the development version.
cderv commented 2 years ago

Thanks for the report. It seems like and issue with Pandoc

Using

❯ echo "![](myplot.pdf)" | pandoc -t revealjs
<section class="slide level6">

<p><embed data-src="myplot.pdf" /></p>
</section>

❯ echo "![](myplot.pdf)" | pandoc -t html
<p><embed src="myplot.pdf" /></p>

<embed> needs a src attribute and not a data-src. The latter is used for revealjs and this make the element not work.

It could be a special treatment by revealjs for Lazy Loading but it does not seem to work for embed element. https://github.com/hakimel/reveal.js/blob/f7c59649fe9d72a148860220a66511cefd142907/js/controllers/slidecontent.js#L52-L59

cderv commented 2 years ago

I have opened an issue in Pandoc https://github.com/jgm/pandoc/issues/7830