When using marimo.App.run to run a notebook, allow specifying which cell outputs you need

Open
#10,694 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
tooling

Research direction

Look at the marimo.App.run function in the codebase to understand its current behavior. The change involves modifying this function to accept a targets parameter and implementing logic to compute and execute only the transitive dependency closure of those targets. Start by examining how the notebook's cell dependencies are tracked and executed. The existing return type must be preserved, and an error should be raised for unknown targets.

Written by the indexing model from the issue text.

Description

enhancement needs discussion
Description

Currently the marimo.App.run function just takes which variables you want to override. But the notebook being called might have a bunch of charts or other output cells that don't need to run.

I propose adding an optional targets: Sequence[str] | None = None argument to marimo.App.run(). When supplied, each target is an existing notebook definition name. Run setup cells and only the transitive dependency closure needed to compute those definitions; leave targets=None behavior unchanged. Preserve the existing return type and raise an informative error for unknown targets.

Are you willing to submit a PR? (You must receive approval from the team before submitting a PR.)
  • Yes (I don't have a PR started or anything, but I could take a crack at it if it came to that)
Alternatives

Alternatives would include:

  • Extract the analysis being performed entirely into reusable functions. The problem is that there are various constants and calculated values that end up getting pulled into the functions as available variables, and then the functions aren't reusable any more.
  • Show the charts in a separate notebook. This is possible, but showing tables and charts right next to the algorithm being developed really helps, and breaking that up would hurt the usability of Marimo notebooks.
Additional context

targets selects existing definition names, not cell IDs or display-only cell outputs. To target a chart or other displayed value, bind it to a definition in the notebook.

targets=None must preserve the current behavior. When targets is provided, marimo executes setup cells and the selected definitions' transitive dependencies; unrelated cells do not execute.

This is an execution-selection option, not a second output-selection API. The existing return type is preserved. Side effects in cells outside the selected dependency closure are not run.

Dominant language
Python
Stars
22.9k
Forks
1.3k
Avg merge
1d 10h
Merged PRs (30d)
380

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from marimo-team/marimo

All issues in marimo-team/marimo

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.