Why have a website

R Markdown websites provide the perfect opportunity to present projects you are working on. They are based on Rmd scripts that you write to run your analyses, so once you’ve set your website up it is easy to update it as you write your code. The main advantages of rendering your Rmd scripts into a website are:




What you will need

To build an R Markdown website you will need:

Here we will focus only on building the website, so there are no instructions on how to set up your GitHub account and getting it synced with your local machine.

Note: The name of the mandatory files needs to be exactly as specified above, so that the files are recognized when you use the command rmarkdown::render_site() to render your website.




Configuration

The _site.yml file is used to configure how your website is generated. Below are two examples of _site.yml files.

Example 1 shows how a _site.yml file (left), and what the corresponding website (right) looks like. In that example we have the following fields:

Example 2 has a few extra fields, namely:

Example 1

Image source: R Markdown Websites page




Example 2





Step-by-step instructions to build and publish your website

Build website

  1. Create a folder for your project in your local computer. This is where you will save all the scripts that make your website.
  2. Create the _site.yml file. Remember to set the output_dir as “.” (see example 2, above).
  3. Create the index.Rmd file
  4. Create any other Rmd files that will generate additional pages/tabs for your website and specify where they go and what they should be called in the _site.yml.
  5. If you are in the directory with all your Rmd scripts, build your website with rmarkdown::render_site(). Otherwise specify the directory when you execute that command. For example: rmarkdown::render_site(input="/Path/to/directory")

When you finish running these steps, you will have all the files that make up your website in the directory you specified. If you open the index.html file, for example, you will see a local version of your website.




Publish website

Once you created your local version of the website, you need to sync the project directory with GitHub. Then, follow the steps below to publish your website:

  1. Login to your GitHub account
  2. Go to the repository containing your website files
  3. Go to settings
  4. Scroll down to the “GitHub Pages” section
  5. Select the “master branch” as the source (i.e. the master branch should contain all your website files, including the _site.yml and index.html).

After a few minutes, your website will be published and the corresponding URL will be displayed in the “GitHub Pages” section in green background (see example below).

img

Note: It can take up to 20 minutes for changes to your site to publish after you push the changes to GitHub.

Note: Even if your GitHub repository is private, the website will be public, i.e. other people won’t be able to see the files on your GitHub repository but they will be able to see the website if given the link.


Useful resources

There are many features that you can add to your website. Below is a list of links to useful online resources that you can explore to build your R Markdown website.

R Markdown Website instructions
Getting started with R Markdown
Markdown Basics
Intro to R Markdown by Yan, Florian & Baptiste
R Markdown Cheat Sheets
R Markdown Website example1
R Markdown Website example2