Created
June 22, 2023 12:33
-
-
Save yjunechoe/1c8cf5e35eaa6dd439c9802cd4396ce7 to your computer and use it in GitHub Desktop.
Example of interactive grouped summary in Quarto using Arquero
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Interactive aggregation" | |
format: html | |
editor: visual | |
--- | |
## Define data | |
```{r} | |
ojs_define(mydata = palmerpenguins::penguins) | |
``` | |
## View data in JS | |
```{ojs} | |
import { aq, op } from '@uwdata/arquero' | |
mytable = aq.table(mydata) | |
mytable.view() | |
``` | |
## Interactivity | |
Input: | |
```{ojs} | |
viewof groupingvars = Inputs.checkbox( | |
["species", "island", "sex"] | |
) | |
``` | |
Output: | |
```{ojs} | |
mytable | |
.groupby(groupingvars) | |
.filter(d => d.body_mass_g > 0) | |
.rollup({ | |
count: op.count(), | |
avg_mass: op.average('body_mass_g') | |
}) | |
.view() | |
``` |
Author
yjunechoe
commented
Jun 22, 2023
## Interactivity2
Input:
```{ojs}
viewof counter = Inputs.button([
["Increment", value => value + 1],
["Decrement", value => value - 1],
["Reset", () => 0]
], {label: "Counter", value: 0})
```
Output:
```{ojs}
aq.addFunction('mySquare', x => x * x);
mytable
.params({
counter: counter
})
.groupby(groupingvars)
.filter(d => d.body_mass_g > 0)
.rollup({
count: op.count(),
count2: (d, $) => op.count() * $.counter,
count3: (d, $) => op.count() * op.mySquare($.counter),
avg_mass: op.average('body_mass_g')
})
.view()
```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment