This is part of the Scicloj Clojure Data Scrapbook. |
Observable examples - DRAFT
ns index
(:require [codegen :refer [obs]]
(:as kind])) [scicloj.kindly.v4.kind
We will use the draft codegen namespace.
A basic example
Note that we read the data from a file, that we can conveniently generate in Clojure.
We follow a basic example from Quarto’s Observable docs.
(obsdef athletes
'("notebooks/datasets/athletes.csv")
(. (FileAttachment :typed true})))) (csv {
(obs:grid true
'(Plot.plot {:facet {:data athletes
:y "sex"}
:marks [(Plot.rectY athletes
:y "count"}
(Plot.binX {:x "weight" :fill "sex"}))
{0])]})) (Plot.ruleY [
Interactions across components
Here, we reproduce the penguins example from the Quarto docs.
(obs
'(viewof bill_length_minrange [32 50]
(Inputs.:value 35
{:step 1
:label "Bill length (min):"}))
'(viewof islands"Torgersen" "Biscoe" "Dream"]
(Inputs.checkbox [:value ["Torgensen" "Biscoe"]
{:lable "Islands:"}))
'(. (Plot.rectY filtered:y "count"}
(Plot.binX {:x "body_mass_g"
{:fill "species"
:thresholds 20}))
:facet {:data filtered
(plot {:x "sex"
:y "species"
:marginRight 80}
:marks [(Plot.frame)]}))
'(Inputs.table filtered)def penguins (. (FileAttachment "notebooks/datasets/palmer-penguins.csv")
'(:typed true})))
(csv {def filtered (. penguins
'(filter [:js "function(penguin) {
( return bill_length_min < penguin.bill_length_mm &&
islands.includes(penguin.island);
}"]))))