Skip to content

Commit df9eea1

Browse files
committed
Initial commit
0 parents  commit df9eea1

File tree

74 files changed

+91635
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+91635
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata
5+
_publish.yml
6+
7+
/.quarto/

00-quarto-observable-basics.qmd

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
---
2+
title: "Quarto Tests"
3+
format:
4+
html:
5+
toc: true
6+
toc-title: "TOC"
7+
css: ./css/style.css
8+
code-fold: true
9+
---
10+
11+
# Quarto Tests
12+
13+
> deploy with `quarto publish quarto-pub 00-quarto-observable-basics.qmd`
14+
15+
## TODOs
16+
17+
- [ ] [Query Database](https://observablehq.com/@observablehq/databases)
18+
- [ ] Document publishing to quartopub.com with `quarto publish quarto-pub <filename>.qmd`
19+
20+
## Syntax Sugar bytes
21+
22+
:::{}
23+
I'm a `div` but R will wrap me within a `<p></p>`
24+
:::
25+
26+
:::{.callout-note}
27+
Note that there are five types of callouts, including:
28+
`note`, `warning`, `important`, `tip`, and `caution`.
29+
:::
30+
31+
:::{.callout-warning}
32+
I'm a `div` but R will wrap me within a `<p></p>`
33+
:::
34+
35+
:::{.callout-important}
36+
Funny how `important` is more urgent than `warning`...
37+
:::
38+
39+
:::{.callout-tip}
40+
## Tip With Caption
41+
42+
This is an example of a callout with a caption.
43+
:::
44+
45+
:::{.callout-caution collapse="true"}
46+
## Expand To Learn About Collapse
47+
48+
This is an example of a 'folded' caution callout that can be expanded by the user. You can use `collapse="true"` to collapse it by default or `collapse="false"` to make a collapsible callout that is expanded by default.
49+
:::
50+
51+
::: {.callout-note icon=false}
52+
53+
## Pay Attention
54+
55+
I'm naked and don't have an icon
56+
57+
:::
58+
59+
::: {.callout-note appearance="simple"}
60+
61+
## Don't Pay Attention
62+
63+
I'm even more minimal
64+
65+
:::
66+
67+
# Test: does R work?
68+
69+
## 1 - Packages
70+
71+
```{r}
72+
#| warning: false
73+
library(tidyverse)
74+
```
75+
76+
## 2 - ggplot
77+
78+
```{r}
79+
#| fig-cap: !expr paste0("Figure caption for this plot, ", lubridate::today())
80+
ggplot(mpg, aes(x = hwy, y = cty, color = cyl)) +
81+
geom_point(alpha = 0.5, size = 2) +
82+
scale_color_viridis_c() +
83+
theme_minimal()
84+
```
85+
86+
# Tabset
87+
88+
::: {.panel-tabset}
89+
90+
## head(mtcars)
91+
92+
```{r}
93+
head(mtcars)
94+
```
95+
96+
97+
## plot(mtcars)
98+
99+
```{r}
100+
plot(mtcars)
101+
```
102+
103+
:::
104+
105+
# R --> ObservableJS
106+
107+
```{r}
108+
labels <- c("Custom Title from R Object", "Custom Label")
109+
ojs_define(labels = labels)
110+
data_processed <- mtcars %>%
111+
tibble::rownames_to_column(var = "brand")
112+
```
113+
114+
```{r}
115+
head(data_processed)
116+
```
117+
118+
## Expose R --> OJS
119+
120+
> notice the `<script type="ojs-define">` entry in the HTML document's `<head />`
121+
122+
```{r}
123+
ojs_define(mtcarsJS = data_processed)
124+
```
125+
126+
```{ojs}
127+
Object.entries(mtcarsJS)
128+
```
129+
130+
## OJS: Inputs.table()
131+
132+
> note the `transpose()`
133+
134+
```{ojs}
135+
Inputs.table(transpose(mtcarsJS))
136+
```
137+
138+
# Bubble Chart
139+
140+
This example uses a D3 bubble chart imported from Observable HQ to analyze commits to GitHub repositories.
141+
142+
Select a repository to analyze the commits of:
143+
144+
```{ojs}
145+
//| echo: false
146+
//| panel: input
147+
viewof repo = Inputs.radio(
148+
[
149+
"tidyverse/ggplot2",
150+
"sveltejs/kit",
151+
"sveltejs/svelte"
152+
],
153+
{ label: labels[0], value: "tidyverse/ggplot2"}
154+
)
155+
```
156+
157+
Fetch the commits for the specified `repo` using the GitHub API:
158+
159+
```{ojs}
160+
//| eval: true
161+
d3 = require('d3')
162+
contributors = await d3.json(
163+
"https://api.github.com/repos/" + repo + "/stats/contributors"
164+
)
165+
commits = contributors.map(contributor => {
166+
const author = contributor.author;
167+
return {
168+
name: author.login,
169+
title: author.login,
170+
group: author.type,
171+
value: contributor.total
172+
}
173+
})
174+
```
175+
176+
Note that the `repo` variable is bound dynamically from the radio input defined above. If you change the input the contributors query will be automatically re-executed.
177+
178+
179+
```{ojs}
180+
Object.entries(commits)
181+
```
182+
183+
View the commits sorted by most to least:
184+
185+
```{ojs}
186+
Inputs.table(commits, { sort: "value", reverse: true })
187+
```
188+
189+
Visualize using a D3 bubble chart imported from Observable HQ:
190+
191+
```{ojs}
192+
import { chart } with { commits as data }
193+
from "@d3/d3-bubble-chart"
194+
chart
195+
```
196+
197+
# Bonus: HTML & reactive CSS Style
198+
199+
```{ojs}
200+
import {x11colors} from "@observablehq/input-select"
201+
```
202+
203+
```{=html}
204+
<details>
205+
<summary>x11colors fallback</summary>
206+
<pre><code>
207+
x11colors = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "green", "greenyellow", "grey", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen"]</code></pre>
208+
</details>
209+
```
210+
211+
```{ojs}
212+
viewof color = Inputs.select(x11colors, {value: "steelblue", label: "Favorite color"})
213+
```
214+
215+
```{ojs}
216+
html`<div style="background: ${color}; width: 100%; height: 25px;">`
217+
```

0 commit comments

Comments
 (0)