Getting down with pagedown: Using R Markdown to create paged HTML documents

Matt Russell, PhD
17 Oct 2019

Twin Cities R User Group

About

The University of Minnesota Arbo Custom Analytics LLC

University of Minnesota, Department of Forest Resources

  • Associate Professor
  • Instruct a graduate class in statstics in natural resources
  • Research and outreach on forest health issues

Arbor Custom Analytics LLC

  • Consulting for the forest products industry.

The value of R Markdown

R Markdown

Markdown integrates text and R code.

  • Reports are fully reproducible
  • Supports static and dynamic output formats (e.g., HTML, PDF, MS Word)
  • Adapted to use R, Python, and SQL languages

R Markdown documents facilitate learning R and statistics

An example of an R Markdown assignment used in a statistics class, page 1.

An example of an R Markdown assignment used in a statistics class, page 2.

R Markdown: more than just documents

  • Themed documents
  • Presentations (like this one!)
  • Books (bookdown)
  • Dashboards (flexdashboard)
  • Websites (blogdown)

bookdown

What is pagedown?

  • Contains output formats for paged HTML documents, letters, resumes, posters, business cards, etc.
  • Uses Paged.js (Javascript library) to paginate web documents
  • Can include headers, footers, and page margins to make elegant documents

The package can be installed from Github:

remotes::install_github('rstudio/pagedown')

New pagedown file in RStudio

  • File -> New File -> R Markdown -> From Template
  • Several templates available

Creating a new pagedown file in RStudio

pagedown:: html_paged

  • Creates a paged HTML document.
  • Can include table of contents and numbered sections.
  • Example: citizen science project showing data.
output:
  pagedown::html_paged: 
    toc: true
    number_sections: true

An example: Cover of a paged HTML document

An example HTML report created with pagedown, page 1

page 1

An example HTML report created with pagedown, page 2

An example HTML report created with pagedown, page 3

pages 2-3

An example HTML report created with pagedown, page 5

An example HTML report created with pagedown, page 6

pages 4-5

An example HTML report created with pagedown, page 7

An example HTML report created with pagedown, page 8

pages 6-7

An example HTML report created with pagedown, page 9

An example HTML report created with pagedown, page 10

pagedown::html_resume

  • Two parts: an Aside and Main section
---
title: "resume_example"
author: "Matt Russell"
output: pagedown::html_resume
---

An example resume created with pagedown

pagedown::business_card

  • Single card for an individual
  • Multiple cards for several employees on the same page
---
name: Matt Russell, PhD
output: pagedown::business_card
---

An example business card created with pagedown

Other pagedown documents

  • Letters
  • Theses/dissertations
  • Posters
  • Journal articles

Other features

  • Cover pages
  • Lists of tables and figures
  • Custom running headers
  • Page references
  • Line numbering

An example journal article created with pagedown

Pros/cons of pagedown

Pros

  • Create high-quality PDFs through a web browser
  • Flexible if you know CSS and Javascript

Cons

  • Works best on Chrome or Chromium
  • May need to use with xaringan to print to web browser (and the “Infinite Moon Reader” function)
xaringan::inf_mr("my_resume.Rmd")

Learn more!

Pagedown documentation

Other applications

Thanks to the main authors Yihui Xie and Romain Lesur and other contributors!