xaringan presentation not displaying html widgets, even when knitting provided template

Created on 18 Jan 2021  Â·  4Comments  Â·  Source: yihui/xaringan

The HTML widgets that are typically functional within xaringan presentations are not showing up / rendering on the slides for me. Even when I knit the provided template. As a reproducible example, when I knit this minimal chunk of the provided template:

title: "Presentation Ninja"
subtitle: "âš”<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

```{r eval=require('DT'), tidy=FALSE}
DT::datatable(
  head(iris, 10),
  fillContainer = FALSE, options = list(pageLength = 8)
)

My slide 2 looks like this: https://i.stack.imgur.com/HsTy1.png

This is true whether I knit in RStudio with the knit button, or use xaringan::infinite_moon_reader(), and the output also looks like this whether I view the .html file from within the RStudio viewer, Firefox, or Safari.

If I change the beginning of the document to be output: ioslides_presentation or html_document, they are rendered perfectly fine within the output. Here is my session info:

> xfun::session_info('xaringan')
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16, RStudio 1.4.1103

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 BH_1.75.0.0     digest_0.6.27  
  evaluate_0.14   glue_1.4.2      graphics_4.0.3 
  grDevices_4.0.3 highr_0.8       htmltools_0.5.1
  httpuv_1.5.5    jsonlite_1.7.2  knitr_1.30.4   
  later_1.1.0.1   magrittr_2.0.1  markdown_1.1   
  methods_4.0.3   mime_0.9        promises_1.1.1 
  R6_2.5.0        Rcpp_1.0.6      rlang_0.4.10   
  rmarkdown_2.6   servr_0.21      stats_4.0.3    
  stringi_1.5.3   stringr_1.4.0   tinytex_0.28   
  tools_4.0.3     utils_4.0.3     xaringan_0.19.1
  xfun_0.20       yaml_2.2.1     

And I just updated RStudio today :
Version 1.4.1103
© 2009-2021 RStudio, PBC
"Wax Begonia" (458706c3, 2021-01-06) for macOS

perhaps also useful:

> rmarkdown::pandoc_version()
[1] ‘2.11.2’

Any advice is appreciated! Thank you all for these wonderful packages!

Note that I originally posted this issue on https://stackoverflow.com/questions/65766516/xaringan-presentation-not-displaying-html-widgets-even-when-knitting-provided-t , where someone else mentioned the same issue and suggested I post here.


By filing an issue to this repo, I promise that

  • [ x] I have fully read the issue guide at https://yihui.org/issue/.
  • [x ] I have provided the necessary information about my issue.

    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.

    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('xaringan'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/xaringan').

    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.

  • [ x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Most helpful comment

I can reproduce this. The problem is related to a recent change in rmarkdown, specifically in version 2.6. The new update now uses pandoc's raw HTML feature to protect the HTML for HTML widgets, but this doesn't work with xaringan because the slides' markdown is processed in the browser by a JavaScript markdown library, not pandoc.

This should probably be fixed in xaringan, but for now you can set the htmltools.preserve.raw option to fix this:

options(htmltools.preserve.raw = FALSE)

You could do this in the setup chunk:

```{r setup, include=FALSE} options(htmltools.dir.version = FALSE, htmltools.preserve.raw = FALSE) ```

All 4 comments

I can reproduce this. The problem is related to a recent change in rmarkdown, specifically in version 2.6. The new update now uses pandoc's raw HTML feature to protect the HTML for HTML widgets, but this doesn't work with xaringan because the slides' markdown is processed in the browser by a JavaScript markdown library, not pandoc.

This should probably be fixed in xaringan, but for now you can set the htmltools.preserve.raw option to fix this:

options(htmltools.preserve.raw = FALSE)

You could do this in the setup chunk:

```{r setup, include=FALSE} options(htmltools.dir.version = FALSE, htmltools.preserve.raw = FALSE) ```

Using options(htmltools.preserve.raw = FALSE) solved my issue, thank you! Should I close this github issue or leave it open since you may still try a fix within xaringan?

I had the same issue @vcannataro, just discovered it this morning. By using options(htmltools.preserve.raw = FALSE), the problem resolved. Thanks for the insight @gadenbuie .

Should be fixed in the development version now:

remotes::install_github('yihui/xaringan')

Thanks for the report! (And thanks @gadenbuie for identifying the root cause!)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tcgriffith picture tcgriffith  Â·  4Comments

ekstroem picture ekstroem  Â·  6Comments

kevinykuo picture kevinykuo  Â·  3Comments

bnicenboim picture bnicenboim  Â·  5Comments

tcgriffith picture tcgriffith  Â·  4Comments