-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_load-data.qmd
More file actions
38 lines (32 loc) · 1.1 KB
/
_load-data.qmd
File metadata and controls
38 lines (32 loc) · 1.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
```{r}
# dataset <- redivis::organization("datapages")$dataset("palmerpenguins")
# penguins <- dataset$table("penguins")$to_tibble()
# ojs_define(data = penguins)
```
```{r}
library(redivis)
quarto <- yaml::read_yaml("_quarto.yml")
# load data from redivis table if specified in yaml
if ("redivis" %in% names(quarto) &&
all(c("user", "table") %in% names(quarto$redivis)) && # need user and table
any(c("dataset", "workflow") %in% names(quarto$redivis))) { # need dataset or workflow
if (!is.null(quarto$redivis$dataset)) {
# use dataset if provided
dataset <- redivis$user(quarto$redivis$user)$dataset(quarto$redivis$dataset)
} else {
# otherwise use workflow
dataset <- redivis$user(quarto$redivis$user)$workflow(quarto$redivis$workflow)
}
# get table data
table <- dataset$table(quarto$redivis$table)
data <- table$to_tibble()
# get variable metadata
vars <- map(table$list_variables(), \(v) c(v$get()$properties, v$get_statistics()))
# pass to OJS
ojs_define(data = data)
ojs_define(vars = vars)
} else {
ojs_define(data = NULL)
ojs_define(vars = NULL)
}
```