.md →
WidgetDAG API#
Lay widgets out as a DAG and draw the arrows -- like mo.hstack, but
columns come from edge depth and the connections are drawn for you.
nodes maps an id to any renderable (an input widget, an image, a chart
-- anything marimo can show). edges is a list of (src_id, dst_id).
layout is (nodes, edges) -> {id: column} (default layered_layout).
The widgets stay live and reactive; this only arranges references to them.
This is a marimo-only display helper: the arrow overlay reaches into marimo's rendered DOM, so it is not wired for plain Jupyter.
Instead of spelling out edges by hand, WidgetDAG.from_widgets derives
them from marimo's own dataflow graph -- pass the widgets and the arrows
follow the notebook's dependency order (see that method).
Example
Source code in wigglystuff/widget_dag.py
from_widgets
classmethod
#
from_widgets(widgets, *, layout=layered_layout)
Build a WidgetDAG from a list of widgets, deriving the arrows from
marimo's dataflow graph.
Pass the widget objects (not their names); each node is labelled with the Python variable it is bound to, and an edge is drawn between two widgets whenever the cell defining one depends on the cell defining the other.
This only works when each widget is a top-level variable defined in its
own cell -- marimo's graph is cell-level, so two variables computed in the
same cell can't be ordered, and inline expressions aren't variables at
all. For those cases use WidgetDAG(nodes, edges) directly. Requires a
running marimo kernel.
Source code in wigglystuff/widget_dag.py
Layout#
A layout is any callable (nodes, edges) -> {id: column}. The default is
layered_layout; pass your own to WidgetDAG(..., layout=...) to swap in a
different algorithm.
Assign each node a column (0 = leftmost).
Longest-path layering, then pull every node rightward to sit just before its earliest child. That keeps edges between adjacent columns for pipeline/tree shapes, so arcs stay inside the empty column gaps and never cross a widget. (True long edges would still skip -- that needs dummy waypoint nodes; a job for a future layout strategy.)
A layout is just (nodes, edges) -> {id: column}; pass your own to
WidgetDAG(..., layout=...) to swap in a different algorithm.
Source code in wigglystuff/widget_dag.py
Notes#
WidgetDAG is a marimo-only display helper. Its arrow overlay reaches into
marimo's rendered DOM to draw connections in the same coordinate space as the
node boxes, so it is not wired for plain Jupyter. The nodes stay live and
reactive — embedding a widget (e.g. a Matrix or Paint) as a node keeps it
interactive, and editing it re-runs the cell that built the DAG.