Publishing a Bookdown Website on Netlify

M. Edward (Ed) Borasky

August 12, 2016

Introduction and Tool Overview

A little about me

  • R programmer
  • Docker fan
  • Twitter veteran @znmeb
  • Daily fantasy sports (DFS) geek @znmeb_dfs

I’m writing a book about daily fantasy sports analytics!

Where do Bookdown and Netlify fit in?

R

“R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS.” – https://www.r-project.org/

The Comprehensive R Archive Network (CRAN)

https://cran.rstudio.com R Installers on CRAN

RStudio®

RStudio use cases / cheatsheets

R Markdown

  • Reproducible document authoring environment
  • Author writes in R Markdown.
    • Markdown + executable code chunks
  • R Markdown renders the document:
    • Markdown is converted to output format(s).
    • Code chunks are syntax highlighted, executed and their results inserted in the output.
  • http://rmarkdown.rstudio.com/

Types of R Markdown outputs

Bookdown

  1. Website: https://bookdown.org/
  2. Textbook: Bookdown: Authoring Books with R Markdown https://bookdown.org/yihui/bookdown/
  3. Demo site / project template: https://github.com/rstudio/bookdown-demo

What is Bookdown?

“The bookdown package is a free and open-source R package built on top of R Markdown to make it really easy to write books and long-form articles/reports. Markdown is a very simple language but made powerful thanks to Pandoc, and bookdown has added a few important missing features related to writing books, such as figure/table caption numbering and cross-references, and embedding HTML widgets or Shiny apps.” - https://bookdown.org/home/about.html

Bookdown outputs

  1. A book website in one of three HTML formats:
    • “GitBook” style - like GitBook with some advanced features
    • “Bootstrap” style - uses the Bootstrap framework / navigation
    • “Tufte” style - text columns with “sidenotes” for equations / graphs
  2. EPUB eBook
  3. With additional software, can make PDFs and Kindle eBooks

Demo

What you will need

  1. A laptop or workstation (Linux, Windows or MacOS)
  2. Git: https://git-scm.com/
  3. A Netlify account: https://app.netlify.com/
  4. The Netlify command line interface: https://www.netlify.com/docs/cli
  5. R: https://cran.rstudio.com
  6. RStudio Preview Release: https://www.rstudio.com/products/rstudio/download/preview/
  7. If you want to make PDFs, you’ll need LaTeX: https://www.latex-project.org/get/

Installing Bookdown

  1. Start RStudio.
  2. In the R console (lower left panel) type install.packages("bookdown", quiet = TRUE). Install bookdown

Creating the project

  1. Clone the RStudio bookdown-demo project: git clone https://github.com/rstudio/bookdown-demo.
  2. Open the project in RStudio (upper right menu). Project Build tab

Edit _output.yml

  • The demo project creates a PDF eBook via LaTeX.
  • If you don’t have LaTeX, you can edit a configuration file called _output.yml and remove the PDF generation code (blue shaded lines): _output.yml

Rendering the book

  1. If you’re not on the “Build” tab in the upper right, select it.
  2. Press the “Build Book” button.
  3. The rendered book website will open in a new window.

Rendered book website

Book Web Page

Book website controls (left to right)

Book website controls

  1. “Hamburger” - toggles display of contents on the left
  2. Search - a search inside the book
  3. Font - selects serif or sans serif, background color
  4. Edit - links to the book’s GitHub repository for editing
  5. Download - links to the downloadable eBook files

Deploying to Netlify

  1. The “Build” creates a directory called _book.
  2. In the “Tools” menu, select “Shell” to open a terminal.
  3. Type

    cd _book
    netlify deploy

It worked!

Successful deploy

Next steps

  1. You’ve deployed the demo from RStudio.
  2. Read Bookdown: Authoring Books with R Markdown.
  3. Use the demo as a template, write your own book.
  4. Deploy.
  5. ????
  6. Profit!

Want some help?

  1. I’m on Twitter! @znmeb
  2. You can file issues at https://gitlab.com/znmeb/dfs.tools/issues/new

License

Note: RStudio® and Shiny® are trademarks of RStudio, Inc. Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.