Get help from the marimo community

Updated 2 months ago

Trigger a cell inside the same notebook

At a glance

The community members are discussing how to trigger a cell inside the same notebook to run again. The original poster mentions looking into Cell.run, but that seems to only work for cells in other notebooks. The comments suggest wrapping the cell in a function and calling that function as a recommended approach. Some community members also mention using self-imports, but note that it can become "wonky". The discussion also touches on the differences between using a cell versus a function, and the potential challenges with reactivity when using closure on wrapped cells.

How can I trigger a cell inside the same notebook to run again? I took a look at Cell.run, but that seems to be only for cells in other notebooks, which are imported to the current notebook.
j
S
M
4 comments
I guess I could just wrap the cell in a function and call that function?
I usually do that, use functions as my building blocks.

I did discover you can self import, but this becomes wonky.
Plain Text
# name this cell hello
print("hi")

Plain Text
from notebook.py import hello
hello()

curious, is there a reason why you would use a cell instead of function
yep, wrapping in a function is recommended, and would be clearer/cleaner when sharing with a co-worker. it will be more obvious what you are doing.
When I have something that I want to call multiple times, I normally wrap it inside a function, and give it the arguments. But by running a cell, I could just reuse the logic of that cell. I am amso not exactly clear as to how reactivity works when using closure on wrapped cells.
Add a reply
Sign up and join the conversation on Discord