---
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
---


```{r, include = F}
# 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)
```



# Hi!

--

This 'minimal flipbook' template has a couple of classic examples to get you building your first flipbooks!

--

flipbooks are code-movies.  The frames of the movies are slides. Here we use the R package {xaringan} to create a remark.js slideshow. 

--

Slide breaks are indicated with `---` (be careful trailing white space is not allowed)

--

flipbookr's `chunk_reveal()` disassembles a single code chunk and creates the "build" of multiple partial-code chunks on different slides (the --- is automatically generated for you too).  

--

We use `chunk_reveal()` it 'inline', not in a code chunk. 

--

Let's start!



---
class: inverse, middle, center


# First up: classic flipbook, using defaults to walk through code pipeline





<!-- get a flipbook version of the my_cars code chunk - pauses are where parentheses are balanced -->
---

`r chunk_reveal("my_cars")`

```{r my_cars, include = FALSE}
cars %>%
  filter(speed > 4) %>%
  ggplot() +
  aes(x = speed) + #BREAK
  aes(y = dist) + #BREAK
  geom_point(
    alpha = .8, 
    color = "blue" 
    ) + 
  aes(size = speed) #BREAK
```

---
class: inverse, center, middle


# Next up:  refer to same chunk, but use user defined breakpoints, and display output only






<!-- get another flipbook version of the my_cars code chunk, this time at the defined breaks and only showing output -->
---

`r chunk_reveal("my_cars", break_type = "user", display_type = "output", title = "### user defined break! using #BREAK message")`



---
class: inverse, center, middle

# Next up:  cycle through different lines of code





<!-- get flipbook that rotates through lines, my_fill -->
---

`r chunk_reveal("my_fill", break_type = "rotate", widths = c(1,1), title = "### cycle through lines of code marked #ROTATE")`

```{r my_fill, eval = F, echo = F}
ggplot(data = cars) +
  aes(x = speed) +
  aes(y = dist) +
  geom_point(size = 8,
             shape = 21,
             alpha = .9,
             color = "snow") +
  aes(fill = speed) +
  scale_fill_viridis_c(option = "magma") + #ROTATE
  scale_fill_viridis_c(option = "cividis") + #ROTATE
  scale_fill_viridis_c(option = "plasma") #ROTATE
```


---
class: inverse, center, middle

# Next up:  look at multiple realizations of same code





<!-- get flipbook that shows multiple realizations of the same code -->
---

`r chunk_reveal("cars_multi", break_type = 5, title = "### see multiple realizations of code")`

```{r cars_multi, include = FALSE}
cars %>% 
  sample_frac(size = 1, replace = TRUE) %>%      
  ggplot() +              
  aes(x = speed) +
  aes(y = dist) +
  geom_count(
    alpha = .7,
    color = "blue",
    size = 4
    ) + 
  geom_smooth(method = lm, se = FALSE) +
  coord_cartesian(xlim = range(cars$speed),
                  ylim = range(cars$dist)) +
  theme(legend.position = c(.9, .2))
```


---

`r chunk_reveal("test", left_assign = "detect")`

```{r test, include=FALSE}
# hello
jam <- "hi"
```



<!-- adjust font size in this css code chunk, currently 80 -->

```{css, eval = TRUE, echo = FALSE}
.remark-code{line-height: 1.5; font-size: 80%}

@media print {
  .has-continuation {
    display: block;
  }
}

code.r.hljs.remark-code{
  position: relative;
  overflow-x: hidden;
}


code.r.hljs.remark-code:hover{
  overflow-x:visible;
  width: 500px;
  border-style: solid;
}
```



---

# Notes: 

- This minimal flipbook assumes you are online when you build and view.  It is going to find the most recent remark.js info online.

- xaringan/remark.js slideshows are not self contained, single file slide shows.  Make sure you ship all the associated files that are created to display your flipbooks/slideshows.  I like to push .html and associated files to github repository and use Github Pages to host for beyond local sharing. :-)

