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

Photo by Vincentiu Solomon

Note: This workflow is not exclusive to xaringan slides! Try it out with any other HTML file.

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

  1. 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

  1. Create a xaringan deck using a xaringan template:
    File > New File > R Markdown > From Template > Ninja Presentation > OK

  2. Delete 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.

  3. Render HTML slides from the open Rmd file using xaringan’s infinite moon reader:

      xaringan::infinite_moon_reader()

Initialize version control with git

  1. 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.

  1. 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.

  1. 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

  1. 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

  1. 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 pointing branch 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.

  1. 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

  1. 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.
  2. 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.)
Silvia P. Canelón
Silvia P. Canelón
Postdoctoral Research Scientist

Biomedical engineer turned informaticist, curious about all intersections of data and society. Pronouns: she/her.

Related