-
Notifications
You must be signed in to change notification settings - Fork 12
/
template.qmd
97 lines (72 loc) · 1.43 KB
/
template.qmd
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
---
title: Quarto Live R Template
format: live-html
engine: knitr
webr:
packages:
- dplyr
- ggplot2
---
{{< include _extensions/live/_knitr.qmd >}}
## Interactive code blocks
```{.webr}
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess")
```
## Interactive exercises
Take the `starwars` dataset and filter so that only characters of species "Droid" are returned.
```{.webr}
#| caption: Sample Exercise
#| exercise: ex_1
starwars |> ______
```
```{.webr}
#| setup: true
#| exercise: ex_1
library(dplyr)
```
::::: { .hint exercise="ex_1"}
::: { .callout-tip collapse="false"}
## Hint 1
Consider using the `filter()` function from `dplyr`.
```r
starwars |> filter(______)
```
:::
:::::
::: { .solution exercise="ex_1" }
**Fully worked solution:**
Use the `filter()` function from `dplyr`:
```r
starwars |> #<1>
filter(species == "Droid") #<2>
```
1. Take the `starwars` dataset, and then,
2. Filter for the "Droid" species.
:::
## Read-only and hidden code blocks
```{.webr}
#| edit: false
mod <- lm(mpg ~ cyl, data = mtcars)
summary(mod)
```
```{.webr}
#| edit: false
#| output: false
foo <- c(1, 2, 3)
bar <- c(4, 5, 6)
```
## Reactive code block inputs
```{ojs}
//| echo: false
viewof n = Inputs.range([10, 300], { step: 1, label: 'n' })
```
```{.webr}
#| startover: false
#| runbutton: false
#| input:
#| - n
2 * n
```