You can render collections of R Markdown documents as a website using the rmarkdown::render_site function. This article describes the basics of creating websites with R Markdown and provides some examples which you can use as a starting point for your own websites.

The features described here are available only within the most recent version of the rmarkdown package (v0.9.6) which you can install from CRAN as follows:

install.packages("rmarkdown", type = "source")

The RStudio IDE also includes integrated support for developing R Markdown websites. These features are available in the current Preview Release of RStudio which you can install from here: RStudio Preview Release.

Simple Example

To start with let's walk through a very simple example, a website that includes two pages (Home and About) and a navigation bar to switch between them:

_site.yml

name: "my-website"
navbar:
  title: "My Website"
  left:
    - text: "Home"
      href: index.html
    - text: "About"
      href: about.html

index.Rmd

---
title: "My Website"
---

Hello, Website!

about.Rmd

---
title: "About This Website"
---

More about this website.

Note that the minimum requirement for any website is that it have an index.Rmd file as well as a _site.yml file. If you execute the rmarkdown::render_site function from within the directory containing the website the following will occur:

  1. All of the Rmd and md files in the root website directory will be rendered into HTML. Note however that markdown files beginning with "_" are not rendered (this is a convention to designate files that are included by top level documents).

  2. The generated HTML files and any supporting files (e.g. CSS and JavaScript) are copied into an output directory (_site by default).

The HTML files within the _site directory are now ready to deploy as a standalone static website.

The full source code for simple example above can be found here: https://github.com/rstudio/rmarkdown-website-examples/tree/master/hello-website.



NVE/Flood_forecasting documentation built on May 7, 2019, 6:04 p.m.