Skip to content

Commit f33da73

Browse files
author
Susan Vanderplas
committed
Starting on javascript
1 parent 4cc0a4e commit f33da73

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

part-advanced-topics/07-intro-interactive-graphics.qmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ There are *many* other options out there - `Observable`, `d3.js`, `highCharts`,
66
While I'd love to include them all, they are all being updated too, which would leave me with a lot of things to maintain to keep this chapter current.
77
Some additional coverage of JavaScript graphics is available in @sec-javascript-graphics.
88

9-
Plotly content is included even though the `plotly` [documentation for R, julia, F#, and Matlab is being deprecated.](https://web.archive.org/web/20251024184918/https://community.plotly.com/t/retire-the-documentation-for-r-matlab-julia-and-f/94147).
10-
Plotly is still a reliable library (and has a lovely `ggplot2` interface), so because [the R package is still being maintained (for now)](https://www.reddit.com/r/rstats/comments/1nto2ir/plotly_is_retiring_its_r_documentation/njh81sw/) I have left it included as part of this chapter.
11-
9+
Plotly content is included even though the `plotly` [documentation for R, julia, F#, and Matlab is being deprecated.](https://web.archive.org/web/20251024184918/https://community.plotly.com/t/retire-the-documentation-for-r-matlab-julia-and-f/94147), because [the R package is still being maintained (for now)](https://www.reddit.com/r/rstats/comments/1nto2ir/plotly_is_retiring_its_r_documentation/njh81sw/) and is supported by Posit.
1210

1311
## {{< fa bullseye >}} Objectives
1412

part-advanced-topics/08-javascript-graphics.qmd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ This is particularly useful when working with interactive graphics.
1919
Observable graphics can be created in two ways: via a hosted service at https://observablehq.com/, and via the Observable JS ("OJS") core library scripts, which can be included into standalone documents (like quarto).
2020
In fact, Quarto handles this natively, and will include the necessary libraries if you use an `{ojs}` executable code block.
2121

22-
First, we have to create an OJS block to read in some data.
22+
First, we do a bit of preprocessing in R to get our data into a form we can use.
23+
2324
```{r}
2425
library(dplyr)
2526
library(tidyr)
@@ -28,9 +29,15 @@ frognames <- read.csv('https://raw.githubusercontent.com/rfordatascience/tidytue
2829
group_by(scientificName) |>
2930
slice_head(n=1)
3031
frogs <- dplyr::left_join(frogid, frognames, by = "scientificName")
31-
write.csv(frogs, file = "../data/frogs.csv", row.names = F)
32+
33+
ojs_define(data = frogs)
3234
```
35+
The last step is to use the `ojs_define()` function in R (also works in python) to make the frogs data available to OJS chunks.
36+
Note that this will not work until the document is compiled, because OJS does not work interactively in quarto notebooks.
37+
3338

3439
```{ojs}
35-
frogs = FileAttachment('../data/frogs.csv').csv({typed: true})
40+
filtered = transpose(data).filter(function(frog) {
41+
return scientificName.includes(frog.scientificName)
42+
})
3643
```

0 commit comments

Comments
 (0)