Get help from the marimo community

Updated 3 weeks ago

Trigger a cell inside the same notebook

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