Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

r

xaringan

The HTML widgets that are supposed to work 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:

---
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
---
options(htmltools.dir.version = FALSE)
DT::datatable(
  head(iris, 10),
  fillContainer = FALSE, options = list(pageLength = 8)
)

All I get for slide 2 is:

screenshot of issue

I would like to include DT::datatable() tables in my presentations. They knit fine to other RMarkdown documents at the moment, like ioslides_presentation and html_document. Here is my session info

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] DT_0.17.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6        rstudioapi_0.13   knitr_1.30.4      servr_0.21        magrittr_2.0.1   
 [6] R6_2.5.0          rlang_0.4.10      fansi_0.4.2       stringr_1.4.0     tools_4.0.3      
[11] xfun_0.20         xaringan_0.19.1   sessioninfo_1.1.1 cli_2.2.0         withr_2.4.0      
[16] htmltools_0.5.1   crosstalk_1.1.1   assertthat_0.2.1  yaml_2.2.1        digest_0.6.27    
[21] crayon_1.3.4      later_1.1.0.1     htmlwidgets_1.5.3 promises_1.1.1    rsconnect_0.8.16 
[26] glue_1.4.2        evaluate_0.14     mime_0.9          rmarkdown_2.6     stringi_1.5.3    
[31] compiler_4.0.3    jsonlite_1.7.2    httpuv_1.5.5  

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!

like image 725
vcannataro Avatar asked Dec 17 '22 11:12

vcannataro


1 Answers

A recent update to rmarkdown (in version 2.6) changed how HTML widgets are included in the output file to use pandoc's raw HTML blocks. Unfortunately, this feature isn't compatible with the JavaScript markdown library used by xaringan. You can disable this feature and resolve the issue with htmlwidgets in xaringan slides by setting

options(htmltools.preserve.raw = FALSE)

Here's the related NEWS entry from rmarkdown 2.6:

Specify that htmltools::htmlPreserve() should use the pandoc raw attribute rather than preservation tokens when pandoc >= v2.0. Note that this option will have the intended effect only for versions of htmltools >= 0.5.0.9003.

like image 60
grrrck Avatar answered May 16 '23 08:05

grrrck