Marimo 101

Reactive notebooks for teaching clinical data science

Piyush Chaudhari

2026-10-22

One lesson, three notebooks

The lesson: SQL on a synthetic OMOP extract, taught through marimo’s features (reactivity, SQL cells, widgets, interactive charts and tables, forms)

The same content, three ways, so you can compare how each tool

  • runs your code
  • handles interactivity
  • gets shared with learners
Version File Run it
Quarto deck (marimo engine) sql-basics.qmd slides
marimo notebook sql-basics-marimo.py molab · in your browser · file
Jupyter notebook sql-basics-jupyter.ipynb Colab · file

All three have the same sections in the same order. The marimo and Jupyter notebooks add a full SQL appendix

Why another notebook?

Jupyter notebooks are great for exploring, but the notebook you see is not always the program that runs

  • Cells can be run in any order
  • Deleting a cell doesn’t delete its variables
  • Widgets only update the cell they live in
  • .ipynb is JSON with outputs inside, so git diffs are noisy

For teaching, that means a student’s notebook can show results that its code no longer produces

In a study of ~1.4 million GitHub notebooks, only 24% ran without errors and only 4% reproduced their saved results

Pimentel et al., MSR 2019

marimo’s answer: make the notebook a reactive program. Each cell declares what it reads and defines, and marimo keeps every output consistent with the code

Hidden state, live

This slide runs marimo on the lesson’s HbA1c results. Move cell A, then compare the two notebooks

  • Jupyter: cell B only reruns when you run it
  • marimo: cell B reruns as soon as threshold changes

The Jupyter notebook has this as a hands-on exercise

How marimo runs a notebook

marimo reads each cell’s code to find the names it defines and the names it reads. That gives a dependency graph

  • Change a cell → marimo reruns everything that depends on it, and nothing else
  • Each global name is defined in one cell
  • Delete a cell → its variables are deleted too
  • UI elements (mo.ui.*) are just variables, so interacting with one reruns the cells that read .value

flowchart TD
    data["<b>data cell</b><br/>con, run()"]
    ui["<b>widget cell</b><br/>yob = mo.ui.range_slider()"]
    sql["<b>SQL cell</b><br/>where_df = mo.sql(...)"]
    chain["<b>SQL cell</b><br/>SELECT … FROM where_df"]
    chart["<b>chart cell</b><br/>reads where_df"]
    data --> sql
    ui --> sql
    sql --> chain
    sql --> chart
    style ui fill:#FA4616,color:#fff,stroke:#FA4616
    style sql fill:#0021A5,color:#fff,stroke:#0021A5
    style chain fill:#0021A5,color:#fff,stroke:#0021A5
    style chart fill:#0021A5,color:#fff,stroke:#0021A5

Move the slider (orange) and only the blue cells rerun

How each notebook is structured

---
engine: marimo
pyproject: |
  dependencies = ["marimo[sql]", "duckdb", "altair"]
---

## UI elements and `.value`

```{python .marimo}
#| echo: true
yob = mo.ui.range_slider(1935, 2005, value=[1950, 1975], label="Year of birth")
yob
```

Markdown with code blocks. Quarto owns the layout (slides, columns, theme); engine: marimo makes the blocks reactive cells that run in the browser

# /// script
# dependencies = ["marimo[sql]", "duckdb", "altair"]
# ///
import marimo
app = marimo.App(css_file="omop-marimo.css")

@app.cell
def _(mo):
    yob = mo.ui.range_slider(1935, 2005, value=[1950, 1975], label="Year of birth")
    yob
    return (yob,)

@app.cell
def _(con, mo, yob):
    where_df = mo.sql(f"""
        SELECT person_id FROM person
        WHERE year_of_birth BETWEEN {yob.value[0]} AND {yob.value[1]}
    """, engine=con)
    return (where_df,)

Plain Python. Each cell is a function: its arguments are what it reads, its return is what it defines. Git-friendly, importable, and it runs with python file.py

{
 "cell_type": "code",
 "execution_count": 7,
 "metadata": {},
 "outputs": [
  {"data": {"text/html": "<div><table border=\"1\" class=\"dataframe\">…"},
   "execution_count": 7, "output_type": "execute_result"}
 ],
 "source": ["@w.interact(yob=w.IntRangeSlider(value=(1950, 1975), …))\n",
            "def where_demo(yob):\n", "    display(run(sql))"]
}

JSON, with outputs and execution counts saved inside. Re-running a cell changes the file even when the code didn’t change

How each notebook runs

Quarto

quarto preview sql-basics.qmd
  • Renders to static HTML with interactive islands
  • Python runs in the viewer’s browser (Pyodide)
  • Viewers can’t edit the code

Open the deck

marimo

uvx marimo edit --sandbox \
  sql-basics-marimo.py
  • A real kernel (local or molab), or the browser
  • The same file is a notebook, an app (marimo run) or a script
  • Learners edit and rerun everything

molab

in your browser

Jupyter

uv run --with jupyterlab … \
  jupyter lab sql-basics-jupyter.ipynb
  • An IPython kernel; you run cells by hand
  • Widgets via ipywidgets callbacks
  • Huge ecosystem; Colab, Binder

Colab

Live examples

Running here, straight from the source files. Every example links to all three versions

Live: widgets drive a query

yob = mo.ui.range_slider(1935, 2005,
                         value=[1950, 1975])
yob
# any other cell
where_df = mo.sql(f"""
  SELECT * FROM person
  WHERE year_of_birth
    BETWEEN {yob.value[0]} AND {yob.value[1]}
""", engine=con)
@w.interact(yob=w.IntRangeSlider(
    value=(1950, 1975), min=1935, max=2005))
def where_demo(yob):
    sql = f"""SELECT * FROM person
      WHERE year_of_birth
        BETWEEN {yob[0]} AND {yob[1]}"""
    display(run(sql))

Widgets and outputs must share one function

Live: one widget builds another

# the slider is built from the dropdown
_cid, lo, hi, default = lab_pick.value
cutoff = mo.ui.slider(lo, hi, value=default)
cutoff

A new lab rebuilds the slider: it’s just another cell

def reset_slider(change):
    _, lo, hi, default = LABS[change["new"]]
    with cutoff.hold_trait_notifications():
        cutoff.min, cutoff.max = lo, hi
        cutoff.value = default
    draw_lab()

lab_pick.observe(reset_slider, names="value")
cutoff.observe(draw_lab, names="value")

Callbacks, an Output widget, and care with min / max

Live: click a chart, query the selection

Click a bar (shift-click for several)

age_chart = mo.ui.altair_chart(
    chart, chart_selection="point")
age_chart
# any other cell
age_chart.value   # selected rows, as a DataFrame
pick = alt.selection_point(fields=["age_band"],
                           name="pick")
age_chart = alt.JupyterChart(
    chart.add_params(pick))      # needs anywidget

def draw_bands(*_):
    sel = age_chart.selections.pick.value
    with band_out: ...

age_chart.selections.observe(draw_bands, ["pick"])

Live: a form that runs once

search = mo.md("{pattern} {ci}").batch(
    pattern=mo.ui.text(value="%chronic%"),
    ci=mo.ui.switch(value=True),
).form(submit_button_label="Search")
# any other cell
mo.stop(search.value is None)
search.value   # {'pattern': ..., 'ci': ...}
@w.interact_manual(
    pattern=w.Text(value="%chronic%"),
    ci=w.Checkbox(value=True),
)
def search(pattern, ci):
    display(run(f"... LIKE '{pattern}'"))

The values exist only inside search()

Live: the whole marimo notebook

sql-basics-marimo.py, exported with marimo export html-wasm and hosted on GitHub Pages. It runs entirely in your browser · open in a new tab · open on molab

Side by side

Quarto + marimo Native marimo Jupyter
File .qmd (Markdown) .py (Python) .ipynb (JSON + outputs)
Execution Reactive Reactive Manual, any order
Hidden state No No Yes
Widgets across cells Automatic Automatic Callbacks
SQL {sql .marimo} blocks SQL cells → DataFrames Strings in Python (or %%sql)
Clickable tables / charts Charts (tables display only) Both Charts via JupyterChart; no built-in table
Where Python runs Pyodide in the browser Local kernel, molab, or Pyodide Local or remote kernel
Learners can edit No Yes Yes (with a kernel)
Git diffs Clean Clean Noisy
Share as Static website molab link, WASM page, app Colab, Binder, nbviewer
Best for Lecture decks, course sites Labs, reproducible analyses, apps Ad-hoc exploration, existing ecosystem

Sharing with learners

molab: marimo’s hosted notebooks, like Colab for marimo

https://molab.marimo.io/github/<owner>/<repo>/blob/<branch>/<file>.py
  • Opens any notebook on GitHub
  • Add /wasm to run it in the viewer’s browser, with no login

GitHub Pages: a static site that runs Python in the browser

uvx marimo export html-wasm sql-basics-marimo.py \
  -o docs/marimo --mode run

Add an empty .nojekyll at the root of the Pages site, or files starting with _ go missing

flowchart LR
    ipynb["sql-basics-jupyter.ipynb"]
    py["sql-basics-marimo.py"]
    qmd["sql-basics.qmd"]
    site["GitHub Pages<br/>(HTML + WASM)"]
    molab["molab"]
    slides["reveal.js slides"]
    ipynb -- "marimo convert" --> py
    py -- "marimo export ipynb" --> ipynb
    py -- "export html-wasm" --> site
    py -- "push to GitHub" --> molab
    qmd -- "quarto render" --> slides
    style py fill:#0021A5,color:#fff,stroke:#0021A5

Resources

About Me

  • I am a PhD Student in Biomedical Informatics at University of Florida, and a Data Management Analyst with UF Health Integrated Data Repository

  • My interests involve uncertainity quantification and propagation in biomedical data and its applications in clinical informatics and decision support systems. I am also very passionate about teaching and advancing education through democratization of data and knowledge

Website | GitHub | Bluesky