Chapter 7 xaringan Presentation

It is a slide template based on an HTML5 presentation framework remark.js.

Basically xaringan injected R Markdown (minus Pandoc) into remark.js. The slides are rendered by remark.js in the web browser, and the Markdown source needed by remark.js is generated from R Markdown (knitr).

You write slides in R Markdown, and then use the xaringan package to render the slides.

Features:

  • Interactive like html notes, but in form of slides, making it equivalent to PowerPoint, which students are more used to.

  • Support the choice of Google fonts.

    Quote Xie, “The best fonts are always the fonts I have never used by myself.” I cannot agree more. 🤣

When you decide to use xaringan, read tutorials HERE.

To create a new xaringan presentation, you simply create a new R Markdown document and use the following YAML header:

---
title: "Presentation Ninja"
subtitle: "with xaringan"
author: "Yihui Xie"
date: "2016/12/12"
output:
  xaringan::moon_reader:
    css: ["xaringan-themer.css", "custom.css"]
    lib_dir: libs
    include:
      in_header: libs/mathjax.html
    nature:
      highlightStyle: github
      highlightLines: yes
      countIncrementalSlides: false
      ratio: '16:9'
---

One slide.

---

Another slide.

xaringan::moon_reader is the main R Markdown output format in the xaringan package.

See the R help page ?xaringan::moon_reader for all possible configurations.

Configurations:

  • lib_dir: The directory to save the dependencies (e.g. jquery, bootstrap, etc.) of the slides.

    This is an argument passed to rmarkdown::html_document. See the help page ?rmarkdown::html_document for additional configurations provided by html_document.

    • By default this will be the name of the document with _files appended to it.
    • Here I set it to be libs.
  • includes: Named list of additional content to include within the document (typically created using the includes function).

    • in_header: Vector of file paths to be included in the document header (inside the <head> tag). Note that paths should be in quotation marks.
    • before_body: Vector of file paths to be included immediately after the opening <body> tag.
    • after_body: Vector of file paths h to be included immediately before the closing </body> tag.

    Include multiple files by passing a vector of file paths.

    includes:
      in_header: ["libs/mathjax.html", "libs/in_header.html"]
      after_body: ["theme/example-numbering.html", "libs/after_body.html"]

    Alternatively, use YAML list indentation with - for each file:

    includes:
      in_header: 
        - libs/mathjax.html
        - libs/in_header.html
      after_body: 
        - theme/example-numbering.html
        - libs/after_body.html

    Each list item is treated as a separate file path.

    ref: https://stackoverflow.com/a/45261469

  • nature: (Nature transformation) A list of configurations to be passed to remark.create(), e.g. list(ratio = '16:9', navigation = list(click = TRUE)).

    See Wiki page of remark.js for all possible configurations.