In a data-analysis notebook, changing a parameter can require you to rerun downstream cells in sequence. Skip one, and the table on screen still reflects the old condition. During exploration, you change the sample count and threshold many times and compare the same aggregate. As the change reaches more cells, missed executions and mismatched results become harder to spot. The more trials you run, the more time you spend managing execution order instead of testing hypotheses. A reactive notebook could follow an input change through its dependent calculations and let you share the finished interface as-is. I used marimo, a reactive Python notebook, to test how far that workflow could go.
marimo is a Python notebook with dependency-based cell recalculation, UI components, SQL cells, and app execution. The marimo project publishes its source under the Apache-2.0 License (*1). I used one synthetic dataset and tested three independent features in sequence: recalculation, SQL, and app delivery.
1. Build the test environment
I kept the tested combination fixed. I left out browser tools used to capture screenshots because they do not affect reproduction. MARIMO_SKIP_UPDATE_CHECK=1 disables the update check that runs in edit mode.
FROM docker.io/library/python:3.12.13-slim
ENV MARIMO_SKIP_UPDATE_CHECK=1
RUN pip install --no-cache-dir --quiet \
'marimo==0.23.14' \
'pandas==2.3.3' \
'numpy==2.5.1' \
'duckdb==1.4.2' \
'sqlglot==26.33.0'
WORKDIR /work
podman build -t marimo-sandbox .
The notebook uses the following notebook.py. It uses the slider value as the row count when it creates a DataFrame, then passes that frame to a statistics table, an interactive table, and a SQL aggregate.
import marimo
app = marimo.App(width="medium")
@app.cell
def __():
import marimo as mo
import numpy as np
import pandas as pd
return mo, np, pd
@app.cell
def __(mo):
n = mo.ui.slider(10, 500, value=100, step=10, label="サンプル数")
n
return (n,)
@app.cell
def __(n, np, pd):
rng = np.random.default_rng(0)
df = pd.DataFrame({
"x": rng.normal(0, 1, n.value),
"y": rng.normal(0, 1, n.value),
"grp": rng.choice(["A", "B", "C"], n.value),
})
df.describe()
return (df,)
@app.cell
def __(mo, df):
table = mo.ui.table(df, label="生成したデータフレーム")
table
return (table,)
@app.cell
def __(mo, df):
result = mo.sql(
f"""
SELECT grp, count(*) AS n, avg(x) AS avg_x, avg(y) AS avg_y
FROM df
GROUP BY grp
ORDER BY grp
"""
)
return (result,)
if __name__ == "__main__":
app.run()
The following command mounts the current directory with read/write access inside the container. Run it in a dedicated empty directory for the experiment. Keep private keys, credentials, customer data, and unreleased source code out of that directory. Bind the port to the host's 127.0.0.1.
podman run --rm \
--memory 2g --cpus 2 --pids-limit 512 \
-p 127.0.0.1:2718:2718 \
-v "$(pwd)":/work:Z -w /work marimo-sandbox \
marimo edit notebook.py --headless --host 0.0.0.0 --port 2718 --no-token
Open port 2718 on 127.0.0.1 in a browser to see the edit screen. With --no-token, keep the port bound to 127.0.0.1.
2. Recalculate downstream cells after a UI change
The initial display shows the slider at 100, and df.describe() in the cell below reports count=100. The slider cell and the cell that creates the DataFrame are separate here.
I moved the slider to its maximum of 500. I did not rerun the DataFrame cell. marimo detected the change in n.value, and count in the statistics table changed to 500 for both columns.
marimo selects dependent cells for recalculation. You can separate the input UI from the calculation without tracking reruns by hand.
3. Aggregate a DataFrame in a native SQL cell
Next, I queried the in-memory pandas DataFrame df through mo.sql(). DuckDB handles execution, so the workflow needs no CSV export or table registration. Grouping 500 rows by grp produced three rows for A, B, and C, with counts of 161, 170, and 169 in that order.
SELECT grp, count(*) AS n, avg(x) AS avg_x, avg(y) AS avg_y
FROM df
GROUP BY grp
ORDER BY grp
grp n avg_x avg_y
A 161 0.023796612980249820 -0.077906248917908950
B 170 -0.040714805905669206 -0.115256957525959030
C 169 -0.061270336951869940 -0.014477743483911202
I hit one snag: a Python column name conflicted with SQL syntax. I first called the group column group, which produced the following DuckDB error.
Parser Error: syntax error at or near ","
LINE 2: SELECT group, count(*) AS n, avg(x) AS avg_x, avg(y) AS avg_y
^
group collided with an SQL reserved word, so renaming the column to grp fixed the query. For existing data with reserved words such as group or order as column names, quote those identifiers or rename the columns before querying.
4. Serve the same file as a read-only app
After editing, change the subcommand from edit to run. Mount the same notebook.py as read-only, retain the resource limits, and bind the port to localhost at runtime.
podman run --rm \
--memory 2g --cpus 2 --pids-limit 512 \
-p 127.0.0.1:2719:2719 \
-v "$(pwd)":/work:ro,Z -w /work marimo-sandbox \
marimo run notebook.py --headless --host 0.0.0.0 --port 2719 --no-token
At port 2719 on 127.0.0.1, the app shows the slider and result tables. marimo hides the code cells and editing controls. The slider remains interactive, so you can change conditions without exposing the calculation logic. I added no separate screen code or export step.
Explore without managing reruns
You split the analysis flow into small pieces when you remember cell execution order after each parameter change and check whether output is current before sharing. You can let marimo's dependency tracking recalculate the cells and hand off the same file as an app. You can focus on hypotheses during exploration and share a results screen with interactive controls and no code. This reduces the work of maintaining separate code and interface. Reviewers get one entry point. A development cycle that lets you test small analyses in short rounds and hand the tested form to the team becomes routine.
Sources
*1 marimo (GitHub), https://github.com/marimo-team/marimo, Apache-2.0 License