Teaching and Learning R using flipbookr package
One of the heart touching R packages that I noted in rstudio::global(2021), 24-hour virtual conference was flipbookr
package developed by Gina Reynolds, Garrick Aden-Buie and Emi Tanaka. Using flipbookr
package you can present your code step-by-step and side-by-side with its output.
This incremental code-output evolution is really helpful to learn how the output changes step-by-step when adding R codes one by one.
How do we create a flipbook?
First install the package from GitHub.
devtools::install_github("EvaMaeRey/flipbookr")
Further, you need
rmarkdown
andXaringan
packages, which you can download directly from CRAN.
To learn more aboutXaringan
package, read this ebook, and this blog post.To create a flipbook, you can use templates available in the package. To access the template called
A Minimal Flipbook
within RStudio, go to
New File -> RMarkdown -> From Template -> A Minimal Flipbook
Open the R Markdown file,
A Minimal Flipbook
. The YAML meta data of this file given below presents an html {xaringan} slide show output.
title: "A minimal flipbook"
subtitle: "With flipbookr and xaringan"
author: "You!"
output:
xaringan::moon_reader:
lib_dir: libs
css: [default, hygge, ninjutsu]
nature:
ratio: 16:9
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
To understand the YAML meta data, knit the
.Rmd
file by giving a name, for example we use the nametest
here. Then, in the current folder, two new folderslibs
andtest_files
will be created.
The header attributes and CSS files are saved in thelibs
folder, and note thatlibs
is the folder name that we have specified in the lib_dir in YAML.
Also, the figures relevant to thistest.Rmd
are saved in thetest_files
folder.The three CSS files mentioned in YAML are,
default
- default CSS for formatting xaringan
hygge
- CSS for further formatting xaringan
ninjutsu
- CSS for the theme for slides.The
ratio
in YAML gives the width and height of the slides.The option
highlightLines: true
ofnature
will highlight code lines, andhighlightStyle: github
use the specific style.Setting the option
countIncrementalSlides:false
will not be displayed a number when each slide is incremented with each new slide.
Next you can see the setup chunk in .Rmd
file. i.e.
# This is the recommended set up for flipbooks
# you might think about setting cache to TRUE as you gain practice --- building flipbooks from scratch can be time consuming
knitr::opts_chunk$set(fig.width = 6, message = FALSE, warning = FALSE, comment = "", cache = F)
library(flipbookr)
library(tidyverse)
Here, we specify the relevant options to ignore showing messages, warnings or comments in slides when running R codes, and we can also set up the width of the figures. Further, we can specify to load {flipbookr}, and other packages that you need for your presentation in this setup chunk.
A new slide will be created with three dashes
(---)
. These dashes must be directly followed by a line break, and there must not be any other characters after the dashes (not even white spaces).A slide properties are written in the beginning of a slide. For example, the
class
property assigns class names to the HTML tag of the slide.
Note that theclass
property in slide 3 is :class: inverse, middle, center
With thisclass
property, we create a slide with theinverse
class CSS to style it, and the content of the slide is in the middle and centered.
Here,.inverse
defines the CSS rules to render text in white on a black background.
.inverse {
background-color: #272822;
color: #d6d6d6;
text-shadow: 0 0 20px #333;
}
Read this to understand the other details of slide properties.
To show content incrementally on a slide, we can use two dashes
(--)
to separate the content as shown in slide 2.Look at the inline
chunk_reveal()
function in slide 4. i.e. r chunk_reveal(“my_cars”)
In thischunk_reveal()
function, only the name of the chunk, which is my_cars, is given, and all other options are default options.We can define the break points in codes using
break_type
option inchunk_reveal()
function. The default setting is “auto”, and it is activated in slide 4 with the given code chunk. We can change the default settings as given here.
To learn more on flipbookr
read the following html slides prepared by Gina Reynolds using flipbookr
package.
To initiate the session, click
once the presentation, and then use the right and left arrows to “flip” through the slides.
If you want to view the slides in full screen, click on the slides and then hit F on your keyboard.
Here is another one:
To understand more, refer the following links:
1.Flipbooks: Presenting code and its output side-by-side and step-by-step.
2. Flipbooks.
3. Embedding a Flipbook Mini in HTML.
4. RStudio video.
5. Use Flipbooks to Explain Your Code and Thought Process.