Is there a recommended way to trigger a cell (which mutates state) to re-run after it's done -- under some conditions?
I was under the impression the following combination of switch/stop would do the trick, but it doesn't seem to be able to escape the infinite loop?
import marimo as mo
import random
import time
get_seconds, set_seconds = mo.state(1)
def expensive_computation():
seconds = get_seconds()
time.sleep(seconds)
set_seconds(random.randint(1,3))
infinite_loop = mo.ui.switch(
False,
label="infinite loop",
)
infinite_loop
mo.stop(not infinite_loop.value)
expensive_computation()
My actual use-case (
https://marimo.io/p/@gvarnavides/iterative-ptychography) is less contrived. Essentially I'd like to plot the output of an iterated map at every iteration. Right now, I'm doing it with
mo.ui.refresh
- which works well, but I'd like a "as quick as possible" update instead of fixed time-increments (since the computation time varies with batch_size).