Recipes

The cookbook: each recipe demonstrates exactly one mechanism in the smallest correct form, meant to be copied. This is the “copy the smallest correct pattern” layer beneath the corpus — where the corpus shows what the system can do, these show how one piece works.

Every recipe runs the same way:

go tool notebook run ./examples/minimal/<name>     # interactive, in a browser
go tool notebook check ./examples/minimal/<name>   # print the dependency graph

Read them roughly top-to-bottom; each builds on the last. Every recipe links to its complete source and to the reference page for the mechanism it isolates. Most are under ~75 lines; a couple (draggable, wrap-existing-package) run longer because they include a full direct-manipulation rendering or a wrapped API surface — the line count is noted so you know which is a one-mechanism recipe and which is a worked example.

Inputs — how a value becomes a control

Recipe Mechanism Lines Reference
hello the whole model: an input cell → a derived cell, wired by name+type 20 quickstart
slider a scalar input; the //notebook:slider directive refines the control 19 controls
checkbox a bool input → a checkbox 24 controls
textinput a string input → a text box 15 controls
selectbox Options() + scalar Value → a select; Reconcile keeps state 45 controls
multiselect Options() + slice Value → a multi 42 controls
rangecontrol Bounds() → a two-handled range control 43 controls
draggable a slice Value + Grip() → points you drag on a chart (worked example) 135 controls
table a slice-of-struct Value → an editable grid 65 controls

Outputs — how a value is drawn

Recipe Mechanism Lines Reference
htmlcard a text/html Render() — the gentlest rich output; uses the optional nb package 45 rendering
svgchart an image/svg+xml Render() — the low-level, zero-import route 44 rendering
sales-analysis normal analysis end-to-end: parse → filter → summarize → nb/chart Table + Bar, no dataframe (worked example) 206 charts

Getting data in

Recipe Mechanism Lines Reference
embedded-data go:embed a dataset (compile-time → still WASM-able), parse with strings 74 charts
csv-native os.Open + encoding/csv with honest (rows, error); native-only 125 charts
file-and-artifact both I/O seams outside the cells: go:embed in (WASM-able), a sibling program that imports the cells and writes a .svg out 119 + writer build & run

Graph shape and behavior

Recipe Mechanism Lines Reference
fanout one result feeding many cells (a forking graph) 23 design
fanin many results feeding one cell (a joining graph) 22 design
errorcell a (value, error) cell, partial failure, blocked-upstream 50 design
cancel context.Context injection, cancellable recompute 40 design
multi-file-package a notebook spanning several .go files: only one carries //go:notebook, but cells use types/methods/helpers from the sibling files — it is an ordinary Go package 3 files design
wrap-existing-package a thin reactive view over a mature Go API: cells just call the existing package (here stdlib regexp) — you wrap your code, you don’t rewrite it 195 design

Build, run, feed, test

Recipe Mechanism Lines Reference
headless the same file as an interactive app and a --headless --set --json batch job 50 build & run
setport the minimal live feed: a driver POSTs one leaf, a pure cell reacts 23 + driver ports
testing cells tested as ordinary Go functions (go test) 52
component-host a foreign page drives a WASM notebook through the JS client — its own layout, subscribeValues for typed output, no built-in UI (worked example) index.html + app.js JS client
notebook-in-notebook embed a live notebook as an interactive figure inside another — a text/html Render iframe to the inner notebook’s ?embed view; composition without an import (the allowed “notebook as a component” direction, not the forbidden nested graph) 55 rendering

Two things every recipe shows