7.4 Build and preview slides
You can knit the source document like other Rmd documents to view the output, but it may be tedious to have to knit it over and over again whenever you make changes. The other way to preview the slides is the RStudio addin “Infinite Moon Reader” or the function xaringan::inf_mr()
, as mentioned in Section 2.2. With this way, you can continuously preview your slides just by saving the source document. The continuous preview is achieved via a local web server launched by the servr package (Xie 2023c).
One distinction of xaringan::moon_reader
when compared to other R Markdown output formats is that it does not generate self-contained HTML documents by default (see Section 3.1.9). This means none of the external dependencies such as images or JavaScript libraries will be embedded in the HTML output file by default. You can turn the self-contained mode on via:
output:
xaringan::moon_reader:
self_contained: true
Due to technical difficulties (remark.js does not use Pandoc but renders Markdown in real time in the browser), it is challenging to implement the self-contained mode really well. Currently, most JavaScript libraries (including remark.js) and CSS files should be correctly embedded in the self-contained mode. Images in slides should also be embedded. The paths of images in slides are identified from ![](PATH)
(Markdown syntax), <img src="PATH" />
(HTML syntax), and background-image: url(PATH)
(remark.js syntax for background images). Other types of images will not be discovered or embedded.
If you have to publish the slides to a web server, but xaringan’s self-contained mode fails to identify certain resources and embed them, please feel free to file an issue to the GitHub repository at https://github.com/yihui/xaringan. If you publish slides to GitHub Pages or Netlify, this may not be a problem, because you can commit or upload all resources files generated or required by the slides.