anywidget is the smallest possible Jupyter widget framework: a Python class with traits + a JS module that exports a render({model, el}) function. The Python state syncs to the JS, the JS renders into a DOM element, and click handlers call model.set(...) to push state back.
On this page, you’re looking at one running with no kernel attached — the page is plain static HTML served from GitHub Pages. Click +/- and the count updates locally.
This site uses an experimental MyST plugin (plugins/anywidget-static-export.mjs) that rewrites notebook widget outputs into something the @myst-theme/anywidget renderer can mount on a static page.
The widget¶
widgets/counter_widget/widget.py is a 30-line anywidget.AnyWidget subclass with value, label, widget_id traits. The matching widget.js exports a render({model, el}) that draws the box and wires +/-/Reset buttons to model.set('value', ...).
import sys
import pathlib
sys.path.insert(0, str(pathlib.Path().absolute().parent))
from widgets.counter_widget import CounterWidgetConstruct one and display it:
CounterWidget(
label="My first static counter",
widget_id="static_counter_demo",
value=5,
)