Skip to content

Commit

Permalink
Reorganise documentation examples
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Jul 4, 2024
1 parent c4927ff commit f6f2fb3
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 146 deletions.
5 changes: 3 additions & 2 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ website:
- href: index.qmd
- section: Getting Started
contents:
- getting_started/setup.qmd
- getting_started/editor.qmd
- getting_started/packages.qmd
- getting_started/plotting.qmd
- getting_started/readonly.qmd
- getting_started/python.qmd
- section: Exercises and Grading
contents:
- exercises/exercises.qmd
Expand All @@ -24,9 +22,11 @@ website:
- exercises/localstorage.qmd
- exercises/grading.qmd
- exercises/gradethis.qmd
- exercises/python.qmd
- section: Interactive Documents and Tutorials
contents:
- interactive/reactivity.qmd
- interactive/python.qmd
- interactive/data.qmd
- interactive/dynamic.qmd
- interactive/define.qmd
Expand All @@ -35,6 +35,7 @@ website:
- other/tables.qmd
- other/resources.qmd
- other/html.qmd
- other/python.qmd
- other/slides.qmd

theme:
Expand Down
10 changes: 9 additions & 1 deletion docs/exercises/gradethis.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Grading solutions using `gradethis`
title: Grading R code using `gradethis`
format: live-html
webr:
packages:
Expand All @@ -9,6 +9,14 @@ webr:
{{< include ../_extensions/live/_knitr.qmd >}}
{{< include ../_extensions/live/_gradethis.qmd >}}

Be sure to include the following to enable grading with `gradethis` in the `knitr` engine.
In a future release, this will no longer be required.

```
{{{< include [...]/_extensions/live/_knitr.qmd >}}}
{{{< include [...]/_extensions/live/_gradethis.qmd >}}}
```

```{webr}
#| edit: false
#| output: false
Expand Down
28 changes: 17 additions & 11 deletions docs/exercises/grading.qmd
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
---
title: Grading Solutions
title: Grading Submitted Solutions
format: live-html
---

## Fill in the blanks

```{webr}
#| caption: Sample Exercise 1
#| exercise: example_1
mtcars |> ______
```

## Grading R code

Write a function to return the number 2.

```{webr}
#| caption: Sample Exercise 2
#| exercise: example_2
#| exercise: example_1
foo <- function () {
return(4)
}
```

::: { .solution exercise="example_1" }

**Fully worked solution:**

```r
foo <- function () { #<1>
return(2) #<2>
}
```
1. Define the function `foo`, and then,
2. Return the number 2.

:::

```{webr}
#| exercise: example_2
#| exercise: example_1
#| check: true
if (!is.function(.result)) {
list(correct = FALSE, message = "I can't see your function!")
Expand Down
4 changes: 3 additions & 1 deletion docs/exercises/localstorage.qmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
title: Editor local storage
title: Editor Local Storage
format: live-html
---

Make a change, run the code, then refresh the page. The latest code should be remembered.

```{webr}
#| localstorage: true
123
Expand Down
30 changes: 12 additions & 18 deletions docs/exercises/python.qmd
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
---
title: Grading Solutions in Python
title: Grading Python Solutions
format: live-html
---

## Grading Python code

```{ojs}
//| output: false
goal = Math.floor(Math.random() * 100);
```

```{ojs}
goal2
```


Write a function to return the number ${goal}.

```{pyodide}
#| caption: Sample Exercise 1
#| input:
#| - goal
#| define:
#| - goal2
#| exercise: example_1
display(goal)
goal2 = goal + 1
def foo():
return 2
```

```{pyodide}
#| exercise: example_1
#| solution: true
def foo():
return ${goal}
::: { .solution exercise="example_1" }

**Fully worked solution:**

```python
def foo(): #<1>
return ${goal} #<2>
```
1. Define the function `foo`, and then,
2. Return the number ${goal}.

:::

```{pyodide}
#| exercise: example_1
Expand All @@ -49,4 +44,3 @@ else:
feedback = { "correct": False, "message": "Incorrect, sorry!" }
feedback
```

3 changes: 2 additions & 1 deletion docs/getting_started/editor.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ rnorm(10)
::: {#lst-ref}

```{.webr}
rnorm(20)
mod <- glm(mpg ~ cyl, data = mtcars)
summary(mod)
```

:::
Expand Down
57 changes: 51 additions & 6 deletions docs/getting_started/plotting.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,66 @@ format: live-html
webr:
packages:
- ggplot2
pyodide:
packages:
- matplotlib
- pandas
- nbformat
- mizani==0.9.2
- plotnine==0.10.1
- seaborn
---

```{webr}
#| edit: false
#| output: false
library(ggplot2)
```
## R

```{webr}
plot(rnorm(1e5), t='l')
```

```{webr}
#| fig-width: 600
#| fig-height: 100
#| fig-height: 150
library(ggplot2)
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point()
```

## Python

```{pyodide}
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(170, 10, 250)
plt.hist(x)
plt.show()
```

```{pyodide}
#| autorun: false
import seaborn as sns
sns.set_theme(style="ticks")
df = sns.load_dataset("anscombe")
sns.lmplot(
data=df, x="x", y="y", col="dataset", hue="dataset",
col_wrap=2, palette="muted", ci=None,
height=4, scatter_kws={"s": 50, "alpha": 1}
)
plt.show()
```

```{pyodide}
#| autorun: false
from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap
from plotnine.data import mtcars
(
ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
+ geom_point()
+ stat_smooth(method="lm")
+ facet_wrap("gear")
)
```
66 changes: 0 additions & 66 deletions docs/getting_started/python.qmd

This file was deleted.

27 changes: 0 additions & 27 deletions docs/getting_started/setup.qmd

This file was deleted.

15 changes: 13 additions & 2 deletions docs/index.qmd
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
---
title: Installation
format: live-html
---

## Installation

```bash
quarto add r-wasm/quarto-live
```

```yaml
---
format: live-html
---
```

Include the folloing line when using the `knitr` engine. This will no longer be required once [#10169](https://github.com/quarto-dev/quarto-cli/issues/10169) has been implemented in Quarto.

```md
{{{< include ./_extensions/r-wasm/live/_knitr.qmd >}}}
```
7 changes: 2 additions & 5 deletions docs/interactive/python.qmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
title: Grading Solutions in Python
title: Reactivity in Python
format: live-html
---

## Grading Python code

```{ojs}
viewof n = Inputs.range([0,100], {step: 1})
viewof n = Inputs.range([0,1000], {step: 1})
```

Write a function to return the number ${goal}.
Expand All @@ -22,5 +20,4 @@ x = np.random.normal(170, 10, n)
plt.hist(x)
plt.show()
plt.show()
```
Loading

0 comments on commit f6f2fb3

Please sign in to comment.