Deploying xaringan Slides: A Ten-Step GitHub Pages Workflow
A ten-step workflow for creating an HTML xaringan slide deck and deploying it to the web using GitHub Pages
Choose your own adventure
Option 1: Keep reading to make a xaringan slide deck from scratch!
Option 2: Start with an R-Ladies themed xaringan template
I made an R-Ladies themed xaringan template to use as a teaching tool and you are welcome to use/modify it to suit your needs! You can download the files to your machine 👇 and then skip down to Initialize version control with git
usethis::use_course( repo_spec = "spcanelon/RLadies-xaringan-template", destdir = "filepath/for/your/presentation" )
Note: After copying the files to your machine you’ll probably want to rename the file folder to whatever makes sense for your presentation.
Try navigating through the slides ☝️ with your left/right arrow keys and press the letter “P” on your keyboard to see some notes in Presenter View
The Ten-Step Workflow
This workflow assumes you have already connected RStudio to Git and GitHub.1
Packages
This code-through was developed using:
Software / package | Version |
---|---|
R | 4.0.3 |
RStudio | 1.4.1103 |
xaringan |
0.19 |
usethis |
2.0.0 |
install.packages("xaringan")
install.packages("usethis")
Creating your xaringan slide deck
Create a new RStudio project for your presentation:
usethis::create_project("filepath/for/your/presentation/repo-name")
📍 If you’re not sure where you are on your computer, check your working directory with
getwd()
and use it as a filepath reference point
Create a xaringan deck using a xaringan template:
File > New File > R Markdown > From Template > Ninja Presentation > OKDelete what you don’t need and save your R Markdown file with whatever name you like. If you pick
index.Rmd
the live link you share at the end will be relatively short.Render HTML slides from the open Rmd file using xaringan’s infinite moon reader:
xaringan::infinite_moon_reader()
Initialize version control with git
Initialize version control of your slides with git:
usethis::use_git()
You’ll be asked if you want to commit the files in your project (with the message “Initial commit”) and then if you want to restart to activate the Git pane. Say yes to both ✅
Note: At the moment {usethis} names the primary branch “master” by default. Issue #1341 suggests the option to instead name it “main” is in the works.
Connect your local project with a GitHub repo:
usethis::use_github()
You could use the function argument
private = TRUE
to create a private GitHub repository. But you may have to remember to change the visibility before deploying to GitHub Pages.
Your new GitHub repo with all of your xaringan project files will automatically open up in your browser
Repo for the R-Ladies xaringan template:
https://github.com/spcanelon/RLadies-xaringan-template
Making and committing changes to your slides
Edit your slides as you wish. Commit often! And then push to GitHub. Use the tools provided by the Git pane in RStudio, or use the following commands in the Terminal:
# Step 1: Stage all modified files git add .
# Step 2: Describe the changes you made to your files git commit -m "<A brief but descriptive commit message>"
Consider writing a commit message that finishes the following sentence:2 “If applied, this commit will…” (e.g. “Change the slide theme”, “Add hello slide”)
# Step 3: Push the changes to your GitHub repository git push
Deploying your slides
When you’re ready to deploy your slides, you can use the
usethis::use_github_pages()
function which makes the process of deploying via GitHub Pages super easy. I recommend pointingbranch
to the name of your primary branch.usethis::use_github_pages(branch = "master")
Note: Your repository must be public for your deployed slides to be available publicly, unless you have a paid GitHub account.
Also, you only need to follow this step once to deploy your slides to the web. As long as you remember to push to your repo any changes that you make to your slides (Rmd and HTML), GitHub Pages will know how to render them.
Visit the link provided to see your newly deployed slides! 🚀
Don’t panic if you don’t see them right away, sometimes it takes a little time. This is the link you will share with the world when you present. Notice it looks very similar to your GitHub repo link.Link to the R-Ladies xaringan template rendered slides:
https://spcanelon.github.io/RLadies-xaringan-template
Bonus steps
- Go to the repository home page and find the About section on the right hand side. Add a description of your presentation and the link to your slides, that way your presentation is easily available to anyone visiting your repo.
- Check out Garrick Aden-Buie’s blog post Sharing Your xaringan Slides to learn how to create a social media card for your slides and use your new link to share your slides in more places (e.g. embedded on a website, etc.)
Learn more
Foundation
- Sharing Your Work with xaringan • Silvia Canelón – workshop site
- Introducción al Paquete xaringan • Silvia Canelón – R-Ladies Meetup
- Making Slides with R Markdown • Alison Hill – workshop slides
- Presentation Ninja • xaringan Official Document – package documentation
- Chapter 7 xaringan Presentations • R Markdown: The Definitive Guide – book chapter
Making your slides extra special
- Home · yihui/xaringan Wiki • GitHub – wiki of customizations for xaringan
- Making Extra Great Slides • Garrick Aden‑Buie – talk & slides with xaringan overview and featuring CSS styling and xaringanthemer
- Applying design guidelines to slides with {xaringanthemer} • katie jolly – blog post
- A playground of extensions for xaringan • xaringanExtra – package site
- Custom xaringan CSS Themes • xaringanthemer – package site