import marimo __generated_with = "0.10.14" app = marimo.App(width="medium") @app.cell def _(): import marimo as mo from asyncio import sleep return mo, sleep @app.cell def _(mo): value = mo.ui.slider(0, 10) value return (value,) @app.cell async def _(sleep, value): for i in range(10): print(value.value, end=" ") await sleep(0.5) return (i,) if __name__ == "__main__": app.run()
import marimo __generated_with = "0.10.14" app = marimo.App(width="medium") @app.cell def _(): import marimo as mo from asyncio import sleep return mo, sleep @app.cell def _(mo): value = mo.ui.slider(0, 10) value return (value,) @app.cell async def _(sleep, value): current = value.value for i in range(10): # Stop if slider value has changed from when we started mo.stop(current != value.value) print(current, end=" ") await sleep(0.5) return (i,) if __name__ == "__main__": app.run()
mo.stop
, but it does not work. It seems that value.value
does not change until after the loop finishes executing0 0 0...
. When it reaches 5 zeros (0 0 0 0 0
), change the slider to 1. It clears the 0 0 0 0 0
and starts printing 1 1 1...
0 0 0 0 0
), change the slider to 1. It keeps on printing until it reaches 10 zeros, then it clears the output and reexecutes printing ones.mo.stop
might not work because the python side of the slider does not change it's value until the current execution of a cell ends?