-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxaringan_example.Rmd
More file actions
2005 lines (1276 loc) · 32.1 KB
/
xaringan_example.Rmd
File metadata and controls
2005 lines (1276 loc) · 32.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Making Slides with R Markdown"
subtitle: "Meet xaringan"
author: "Alison Hill"
date: "2019/01/15 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
css: ["default", "css/sfah.css", "css/fonts.css"]
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
ratio: "16:9"
beforeInit: "https://platform.twitter.com/widgets.js"
seal: false
includes:
in_header: header.html
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
library(knitr)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
# options(knitr.table.format = "html")
library(tidyverse)
library(babynames)
library(fontawesome) # from github: https://github.com/rstudio/fontawesome
library(DiagrammeR)
```
layout: true
<div class="my-footer"><span>arm.rbind.io/slides/xaringan</span></div>
<!-- this adds the link footer to all slides, depends on my-footer class in css-->
---
name: xaringan-title
class: left, middle
background-image: url(img/brooke-lark-500141-unsplash.jpg)
background-size: cover
# Meet xaringan
<img src="https://user-images.githubusercontent.com/163582/45438104-ea200600-b67b-11e8-80fa-d9f2a99a03b0.png" alt="Sharingan" width="180" />
### .fancy[Making slides in R Markdown]
.large[Alison Hill | rstudio::conf | `r Sys.Date()`]
<!-- this ends up being the title slide since seal = FALSE-->
---
class: middle, inverse
.left-column[
# `r emo::ji("confused")`
]
.right-column[
# /ʃæ.'riŋ.ɡæn/
]
---
class: right, middle
<img class="circle" src="https://github.com/apreshill.png" width="150px"/>
# Find me at...
[`r fa(name = "twitter")` @apreshill](http://twitter.com/apreshill)
[`r fa(name = "github")` @apreshill](http://github.com/apreshill)
[`r fa(name = "link")` alison.rbind.io](https://alison.rbind.io)
[`r fa(name = "paper-plane")` alison@rstudio.com](mailto:alison@rstudio.com)
---
name: setup
class: middle, inverse
# Did you do the <br> .fat[.fancy[pre-work setup?]]
.large[https://arm.rbind.io/prework/]
---
name: usecourse
class: middle, inverse
# Did you download the <br> .salt[.fancy[workshop package?]]
```{r eval = FALSE, echo = TRUE}
remotes::install_github("armcompanion")
```
---
name: ninja
class: middle, inverse
# We assume:
--
### <i class="fab fa-markdown fa-lg fa-fw" style="float:left"/></i> you know Markdown
--
### <img src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/PNG/rmarkdown.png" width="5%" style="float:left"/> you know R Markdown
--
### <i class="fab fa-html5 fa-lg fa-fw" style="float:left"></i> .saltinline[.fancy[you want awesome HTML5 slides]]
---
name: novice
class: middle, inverse
# What you may not know:
--
### <i class="fab fa-js fa-lg fa-fw"></i> JavaScript
--
### <i class="fab fa-css3-alt fa-lg fa-fw"></i> CSS (Cascading Style Sheets)
--
### <i class="fab fa-html5 fa-lg fa-fw" style="float:left"></i> .saltinline[.fancy[you want awesome HTML5 slides]]
---
name: nutshell
class: center, middle
# In a nutshell `r emo::ji("squirrel")`
.pull-left[

]
--
.pull-right[

]
---
name: remark.js
# .center[What is remark.js?]
.pull-left[
.center[
<img src="https://pluralsight.imgix.net/paths/path-icons/javascript-36f5949a45.png" width="40%"/>
and
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/2000px-Markdown-mark.svg.png" width="25%" />
]
]
--
.pull-right[
To create:
> .fancy["A simple, in-browser, markdown-driven slideshow tool targeted at people who know their way around HTML and CSS"]
```{r echo = FALSE}
knitr::include_url("https://remarkjs.com/", height = "300px")
```
]
---
name: but
class: center, inverse, middle
# .fancy[but, remark.js doesn't know R...]
--
# .fancy[remark.js only supports Markdown]
---
name: xaringan
# .center[What is xaringan?]
.pull-left[
.center[
<img src="https://pluralsight.imgix.net/paths/path-icons/javascript-36f5949a45.png" width="25%"/>
and
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/2000px-Markdown-mark.svg.png" width="20%" />
and
<img src="https://raw.githubusercontent.com/rstudio/hex-stickers/master/PNG/rmarkdown.png" width="20%" />
]
]
--
.pull-right[
To create:
> .fancy["An R package for creating HTML5 presentations with remark.js through R Markdown."]
```{r echo = FALSE}
knitr::include_url("https://arm.rbind.io/slides/xaringan.html", height = "300px")
```
]
---
name: diagram
# Hello `r fa(name = "user-ninja", fill = "white")`
With R Markdown, you are used to this:

--
With **xaringan** (no `pandoc`!):
```{r echo = FALSE, out.width = '75%', out.height = "50%"}
# Create a graph as a left-to-right path
graph <-
create_graph() %>%
add_path(
n = 5,
type = "step",
label = c(
"xaringan\\n .Rmd", "knitr", ".md",
"remark.js via\\n xaringan::moon_reader", "html"),
node_aes = node_aes( # set node aesthetics
shape = c("circle", "square", "circle", "rectangle", "circle"),
width = c(0.75, 0.5, 0.5, 2, 0.5),
color = "#3C3C3C",
fontcolor = "black",
fillcolor = c("#61acf0", "#f0a561", "#cbd20a", "#f0a561", "#e74a2f"),
fontname = "Lato"
),
edge_aes = edge_aes( # set edge aesthetics
color = "#3C3C3C"
)
) %>%
add_global_graph_attrs(attr = "layout", value = "dot", attr_type = "graph") %>%
add_global_graph_attrs(attr = "rankdir", value = "LR", attr_type = "graph")
# View the graph in the Viewer
graph %>% render_graph()
```
---
class: inverse, middle, center
# `r fa(name = "user-ninja", fill = "white")`
# .fancy[Let's make a slide deck right now]
--
.pull-left[
### .fancy[.center[Local with GitHub]]
### .fancy[.center[`r emo::ji("computer")` + <i class="fab fa-github fa-lg fa-fw"></i>]]
]
--
.pull-right[
### .fancy[.center[Cloud or Local (no GitHub)]]
### .fancy[.center[`r emo::ji("cloud")` | `r emo::ji("computer")`]]
]
---
name: start-here
class: inverse, middle
.pull-left[
### .fancy[.center[Local with GitHub]]
### .fancy[.center[`r emo::ji("computer")` + <i class="fab fa-github fa-lg fa-fw"></i>]]
1. Make a [repo on GitHub](https://happygitwithr.com/new-github-first.html#make-a-repo-on-github-1)
1. Make a [new RStudio project via git clone](https://happygitwithr.com/new-github-first.html#new-rstudio-project-via-git-clone) <br>
*File > New Project > Version Control > Git*
]
--
.pull-right[
### .fancy[.center[Cloud or Local]]
### .fancy[.center[`r emo::ji("cloud")` | `r emo::ji("computer")`]]
1. Make a new RStudio project via wizard <br>
*File > New Project > New Directory > New Project*
]
--
<hr>
.center[When inside your new project, do:
*File > New File > R Markdown > From Template*
Select .acidinline["arm-xaringan"] from the .heatinline[**armcompanion**] package
]
---
# Let's make this a slide deck
.pull-left[
Where you see:
```{r eval = FALSE}
---
output: html_document #<<
---
```
]
--
.pull-right[
Change to:
```{r eval = FALSE}
---
output: xaringan::moon_reader #<<
---
```
]
--
.pull-right[
Save this!
]
---
# Moon reader `r emo::ji("astronaut")`
Click the `Knit` button to compile it
--
Do you see both slides?
--
- Title slide `r emo::ji("cry")`
--
- Content slide `r emo::ji("rage")`
--
Don't worry: it gets much better. But first...
---
# Infinite moon reader `r emo::ji("rocket")`
- Now use the [RStudio Addin](https://rstudio.github.io/rstudioaddins/)<sup>1</sup> and select _xaringan: Infinite Moon Reader._
--
- Generates live preview the slides (every time you update and save the Rmd document, the slides will be automatically reloaded in RStudio Viewer.)
--
- Be sure to click on the "Show in new window" button in your RStudio viewer pane.
--
- In your browser, see the `...html#41` at the end? Make it `...html#hop` `r emo::ji("rabbit")`
---
name: skip
class: middle, inverse
# .fancy[And we're back!]
This is the power of using:
```{r eval = FALSE}
---
name: something
# This is really something!
```
--
You can [name individual slides](https://github.com/gnab/remark/wiki/Markdown#name), then cross link to them too from other slides in your deck:
`[hop back to the end](#hop)` -> [hop back to the end](#hop)
???
For example, for these slide decks today, I named all the Your Turn slides so that they would be easily linkable.
---
name: keyboard-demo
class: center, inverse, middle
# .fancy[Keyboard shortcuts]
Press `h` or `?` to see the `remark.js` [keyboard shortcuts](https://bookdown.org/yihui/rmarkdown/xaringan-key.html).
--
A useful workflow for presenting; if you have two screens, turn off display mirroring then press `c` to clone:
.pull-left[
# `r fa(name = "desktop", fill = "white")`
On the presentation screen:
Move cloned window to this screen <br>
Then press `f` for full-screen mode
]
.pull-right[
# `r fa(name = "laptop", fill = "white")`
On your laptop screen:
Press `p` for presenter mode on laptop <br>
Wish you had used `???` to add [presenter notes](https://bookdown.org/yihui/rmarkdown/xaringan-format.html#xaringan-notes)
]
???
Don't forget to add presenter notes- when you are in presenter mode you see them but your audience does not! You use three question marks at the bottom of your slide to separate out your notes.
---
name: sfah
class: center, middle
---
template: sfah
## .salt[SALT] .fat[FAT]
## .acid[ACID] .heat[HEAT]
---
name: outline
template: sfah
## .salt[REMARK.JS] [`r emo::ji("link")`](#block1) .fat[CHUNKS] [`r emo::ji("link")`](#block2)
## .acid[IMAGES] [`r emo::ji("link")`](#block3) .heat[THEMES] [`r emo::ji("link")`](#block4)
---
name: salt
class: inverse, middle, center
background-image: url(img/jason-tuinstra-551608-unsplash.jpg)
background-size: cover
# SALT = remark.js
???
SALT enhances flavor
REMARK.JS enhances your code
---
name: block1
# remark.js
What you need to know now:
- [Making slides](#newslide-demo)
- Align [all](#fullalign-demo) or [some slide content](#textalign-demo)
- [Incremental reveals](#increment-demo)
- [Two-column slides](#pull-demo)
---
name: newslide-demo
# Making slides
.pull-left[
- Slide 1 starts where YAML ends
- 3 dashes in a row `---` on a line by itself is a new slide
]
.pull-right[
```
---
title: "armdeck"
output: xaringan::moon_reader
---
# Introduce yourself!
> My name is Alison and I am a Data Scientist & Professional Educator at RStudio. I live in Portland, Oregon with my husband, daughter, and our sourdough starter.
---
# Find me at...
All the details...
```
]
---
name: fullalign-demo
# Align an entire slide
.left-column[
### Horizontal
```
*left,
center,
right
```
<hr>
### Vertical
```
*top,
middle,
bottom
```
]
--
.right-column[
```{r eval = FALSE}
---
class: center, middle #<<
# Slide with centered content in the middle
My name is Alison. I like hot toddies, `#rdogladies`, and babies.
---
```
]
---
class: center, middle
.left[
```
---
class: center, middle
```
]
# Slide with centered content in the middle
My name is Alison. I like hot toddies, `#rdogladies`, and babies.
---
name: textalign-demo
# Align some text only
.left-column[
### Horizontal only
```
.left[words]
.center[words]
.right[words]
```
]
--
.right-column[
```{r eval = FALSE}
---
class: center, middle
# Slide with some aligned text
My name is Alison. I like hot toddies, `#rdogladies`,...
.left[and babies.] #<<
---
```
]
---
class: center, middle
.left[
```
---
class: center, middle
```
]
# Slide with some aligned text
My name is Alison. I like hot toddies, `#rdogladies`,...
.left[and babies.]
---
class: inverse, center, top
background-image: url(img/brooke-lark-500141-unsplash.jpg)
background-size: cover
# .fancy["but you promised us pretty pictures..."]
---
name: mdimage-demo
class: middle
.pull-left[
```{r eval = FALSE}
---
class: center, middle
# Hi there, with an image
My name is Alison. I like hot toddies,
`#rdogladies`, and
 #<<
---
```
]
.pull-right[
.center[.middle[
### Hi there, with an image
My name is Alison.
I like hot toddies,
`#rdogladies`, and
<img class="lil" src="http://bit.ly/momtocat">
]]
]
--
.footnote[
In "real life", you'll often want to use straight-up HTML too:
`<img src="http://bit.ly/wiki-toddy" width="15%" align="right" />`
]
---
name: increment-demo
# Incremental reveals
.left-column[
```
# Hi there
My name is Alison
--
I like hot toddies
--
`#rdogladies`
--
and babies
```
]
--
.right-column[
### Hi there
My name is Alison
{{content}}
]
--
I like hot toddies
{{content}}
--
`#rdogladies`
{{content}}
--
and babies
<!--https://stackoverflow.com/questions/46408057/incremental-slides-do-not-work-with-a-two-column-layout-->
---
name: pull-demo
.left-column[
# Two-columns
```
.pull-left[
...

]
.pull-right[
...

]
```
]
--
.right-column[
.pull-left[
Momtocat on your left

]
.pull-right[
Poptocat on your right

]
]
--
.footnote[
[1] On a full slide, these are each 47% width.
[2] You can also similarly use `.left-column[]` and `.right-column[]`. The sizes are then 20% and 75%, respectively.
]
---
name: section
class: top, inverse
background-image: url(img/jason-tuinstra-551608-unsplash.jpg)
background-size: cover
---
name: yourturn
template: section
.left-column[
# <i class="fas fa-edit"></i> <br>.fancy[Your turn]
]
---
name: yourturn1
template: yourturn
.right-column[
[Season](#block1) some slides with `remark.js` salt! Consider trying:
1. Add [presenter notes with `???`](#keyboard-demo)
1. Incremental reveals with `--` ([demo slide](#increment-demo))
1. Align all content with the `class` slide property ([demo slide](#fullalign-demo))
1. Align some text on a slide with `.left / .center / .right` ([demo slide](#textalign-demo))
1. Create two-column slides with `.pull-left / .pull-right / .left-column / .right-column` ([demo slide](#pull-demo))
]
.left-column[
## .fancy[.saltinline[10:00 minutes]]
]
.footnote[
Don't despair- we'll fatten up our slides with R chunks next...
]
---
name: fat
class: inverse, top, center
background-image: url(img/bake-599521_1920.jpg)
background-size: cover
---
template: fat
# FAT
---
template: fat
# FAT = CHUNKS
---
name: block2
# Chunks
What you need to know now:
- [Highlight your code](#highlightjs-demo)
- [Add a table](#table-demos)
- [Add a plot](#plot-demo)
---
name: highlightjs-demo
# Highlight your code
Why? It makes it more readable `r emo::ji("eyes")`
```{r eval = FALSE}
---
title: "armdeck"
subtitle: "rstudio::conf 2019"
author: "Alison Hill"
date: "`r Sys.Date()`"
output:
xaringan::moon_reader:
nature: #<<
highlightStyle: github #<<
highlightLines: true #<<
---
```
--
The [highlight style options are](https://github.com/gnab/remark/wiki/Configuration):
+ `arta`, `ascetic`, `dark`, `default`, `far`, `github`, `googlecode`, `idea`, `ir-black`, `magula`, `monokai`, `rainbow`, `solarized-dark`, `solarized-light`, `sunburst`, `tomorrow`, `tomorrow-night-blue`, `tomorrow-night-bright`, `tomorrow-night`, `tomorrow-night-eighties`, `vs`, `zenburn`.
---
name: highlight-input
# Highlight code input
.pull-left[
````
```{r tx-wrangle}`r ''`
library(babynames)
library(tidyverse)
tx_names <- babynames %>%
filter(name == "Dallas" |
name == "Austin") %>%
filter(sex == "F")
*glimpse(tx_names) #<<
```
````
]
.pull-right[
```{r tx-wrangle-input, eval = FALSE}
library(babynames)
library(tidyverse)
tx_names <- babynames %>%
filter(name == "Dallas" |
name == "Austin") %>%
filter(sex == "F")
glimpse(tx_names) #<<
```
]
.footnote[
See https://slides.yihui.name/xaringan/#31
Note that to highlight a line of plain markdown text, use a `*` (from [remark docs](https://github.com/gnab/remark/wiki/Configuration))
]
---
name: highlight-output
# Highlight code output
.pull-left[
````
```{r tx-wrangle, highlight.output = 3:4}`r ''`
library(babynames)
library(tidyverse)
tx_names <- babynames %>%
filter(name == "Dallas" |
name == "Austin") %>%
filter(sex == "F")
glimpse(tx_names)