Skip to content

Instantly share code, notes, and snippets.

@gadenbuie
Last active August 28, 2019 21:38
Show Gist options
  • Save gadenbuie/aeb16bd1445bdc1e0294465f46e3de50 to your computer and use it in GitHub Desktop.
Save gadenbuie/aeb16bd1445bdc1e0294465f46e3de50 to your computer and use it in GitHub Desktop.
xaringan slides on repeat
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, Inc."
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
includes:
in_header: repeatSlides.html
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
???
Image credit: [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Sharingan_triple.svg)
---
class: center, middle
# xaringan
### /ʃaː.'riŋ.ɡan/
---
class: inverse, center, middle
# Get Started
---
# Hello World
Install the **xaringan** package from [Github](https://github.com/yihui/xaringan):
```{r eval=FALSE, tidy=FALSE}
devtools::install_github("yihui/xaringan")
```
--
You are recommended to use the [RStudio IDE](https://www.rstudio.com/products/rstudio/), but you do not have to.
- Create a new R Markdown document from the menu `File -> New File -> R Markdown -> From Template -> Ninja Presentation`;<sup>1</sup>
--
- Click the `Knit` button to compile it;
--
- or use the [RStudio Addin](https://rstudio.github.io/rstudioaddins/)<sup>2</sup> "Infinite Moon Reader" to live preview the slides (every time you update and save the Rmd document, the slides will be automatically reloaded in RStudio Viewer.
.footnote[
[1] 中文用户请看[这份教程](http://slides.yihui.name/xaringan/zh-CN.html)
[2] See [#2](https://github.com/yihui/xaringan/issues/2) if you do not see the template or addin in RStudio.
]
---
background-image: url(`r xaringan:::karl`)
background-position: 50% 50%
class: center, bottom, inverse
# You only live once!
---
# Hello Ninja
As a presentation ninja, you certainly should not be satisfied by the "Hello World" example. You need to understand more about two things:
1. The [remark.js](https://remarkjs.com) library;
1. The **xaringan** package;
Basically **xaringan** injected the chakra of 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**).
---
# remark.js
You can see an introduction of remark.js from [its homepage](https://remarkjs.com). You should read the [remark.js Wiki](https://github.com/gnab/remark/wiki) at least once to know how to
- create a new slide (Markdown syntax<sup>*</sup> and slide properties);
- format a slide (e.g. text alignment);
- configure the slideshow;
- and use the presentation (keyboard shortcuts).
It is important to be familiar with remark.js before you can understand the options in **xaringan**.
.footnote[[*] It is different with Pandoc's Markdown! It is limited but should be enough for presentation purposes. Come on... You do not need a slide for the Table of Contents! Well, the Markdown support in remark.js [may be improved](https://github.com/gnab/remark/issues/142) in the future.]
---
background-image: url(`r xaringan:::karl`)
background-size: cover
class: center, bottom, inverse
# I was so happy to have discovered remark.js!
<script>
// Adapted from https://github.com/gnab/remark/wiki/Configuration#using-javascript-to-create-a-continuously-looping-slideshow
// every 8 seconds (change to your desired interval), fire the helper function
document.addEventListener("DOMContentLoaded", function() {
setInterval(function () {carousel(slideshow)}, 8000);
function carousel(varObject) {
var slideCount = varObject.getSlideCount()-1;
var currentSlide = varObject.getCurrentSlideIndex();
// if the slideshow is on the last slide, go back to the first slide; if not, call gotoNextSlide();
if (currentSlide == slideCount) {
varObject.gotoFirstSlide();
}
else { varObject.gotoNextSlide(); }
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment