.md →
WidgetFlow API#
WidgetFlow is a marimo display helper rather than an AnyWidget. It lays live
widgets (or any renderable: charts, images, mo.stat, ...) out as a layered
DAG in the style of FormulaDAG. You pass the widgets and the
arrows between them as pairs of the same objects. You can also skip the edge
list: WidgetFlow.from_widgets([...]) reads the edges off marimo's dataflow
graph and captions each widget with its variable name. The widgets stay live
and reactive, because the flow only arranges references to them.
The layout is in your hands where it matters. Edges take labels, colours,
dashes and explicit exit/enter ports, and ported arrows route around the
other widgets. beside puts a widget next to the one it feeds, layers pins
a widget to a later layer, and align packs every layer onto one shared grid,
so a chain of widgets down a column gets straight arrows. notes hang an
explanatory note beside a widget.
Parts of the flow can be hidden and brought back. Widgets in collapsible
get a hover button that folds them to a pill showing their caption. groups
draw a dashed frame whose tab folds a whole stretch of the flow into one pill,
and the arrows in and out of the group re-aim at the pill. Folding happens in
the browser, so nothing is laid out again and every widget keeps its state.
Nest one WidgetFlow inside another to treat a sub-flow as a single node.
See also: WidgetDAG for a simpler column layout,
FormulaDAG for formulas wired by \use{name}, and
Hint for a single arrow from a note to a widget.
Lay live widgets out as a DAG, in the style of FormulaDAG.
Pass the widgets (or any renderable: charts, images, mo.stat, ...) as a
list, and the arrows between them as pairs of those same objects. The
widgets stay live and reactive; this only arranges references to them. To
skip the edge list, WidgetFlow.from_widgets reads the arrows off
marimo's own dataflow graph.
This is a marimo-only display helper: the arrow overlay reaches into marimo's rendered DOM, so it does not work in plain Jupyter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
The widgets, in reading order. Each object may appear once. |
required | |
edges
|
|
required | |
direction
|
|
'down'
|
|
notes
|
|
None
|
|
ports
|
|
None
|
|
labels
|
Captions under the widgets. |
False
|
|
layers
|
|
None
|
|
beside
|
|
None
|
|
align
|
where each layer's widgets sit. |
'center'
|
|
collapsible
|
Widgets that get a small button (top-right, on hover)
that folds them to a pill showing just their caption, and back.
Arrows keep landing on the pill and nothing else moves. Fold a
nested |
None
|
|
collapsed
|
Widgets that start folded (they're collapsible too). Folding happens in the browser; this only sets where it starts. |
None
|
|
groups
|
|
None
|
|
theme
|
|
'auto'
|
Widgets are referred to by the objects themselves, so options that name a
widget take (widget, value) pairs rather than dicts: charts and marimo
UI elements can't be dict keys.
The look is tweakable from CSS: --wf-edge, --wf-note, --wf-ink,
--wf-layer-gap and --wf-node-gap on the .wf root.
Example
WidgetFlow(
[n_points, noise, data_chart, degree, fit_chart],
edges=[
(n_points, data_chart),
(noise, data_chart, "σ"),
(data_chart, fit_chart, {"label": "x, y", "color": "#c2410c"}),
(degree, fit_chart, {"enter": "right"}),
],
notes=[(noise, "std of the gaussian noise")],
)
Left-align the layers and put degree right of the chart it feeds:
WidgetFlow.from_widgets(
[n_points, noise, data_chart, degree, fit_chart],
align="left",
beside=[(degree, fit_chart)],
)
Let the data chart fold away, and fold the fitting step as a whole, starting folded:
Source code in wigglystuff/widget_flow.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
downstream #
from_widgets
classmethod
#
Build a WidgetFlow whose arrows come from marimo's dataflow graph.
One widget points at another when the cell defining the second depends
on the cell defining the first (transitively reduced, so a chain
a -> b -> c gets no shortcut a -> c). Each widget is captioned
with its variable name unless you pass labels=False or a dict.
Every other keyword is passed to WidgetFlow.
This needs each widget to be a top-level variable in its own cell:
marimo's graph is cell-level, so two variables computed in one cell
can't be ordered, and inline expressions aren't variables at all. For
those, pass edges to WidgetFlow yourself. Requires a running
marimo kernel.
Source code in wigglystuff/widget_flow.py
Folding parts of the flow#
WidgetFlow(
[drawing, X, noise, X_noisy, Z, weights, Y, angle, plots],
edges=[...],
collapsible=[drawing, plots], # hover button on these
groups=[("Z → Y", [Z, weights, Y, angle])], # dashed frame + tab
collapsed=[plots], # start folded
)
A group must include every widget on a path between two of its own widgets, because the pill replaces them all. Arrows that end up joining the same pair of nodes once the group folds stay separate when they land in different spots.
Notes#
WidgetFlow is a marimo-only display helper. Its arrow overlay reaches into
marimo's rendered DOM to draw in the same coordinate space as the widgets, so
it does not work in plain Jupyter. In Jupyter it raises a clear error instead
of printing a silent repr.