Skip to content

Instantly share code, notes, and snippets.

@davipatti
Created March 27, 2025 23:55
Show Gist options
  • Save davipatti/560ad735a2d531d5dddbc61dc572420e to your computer and use it in GitHub Desktop.
Save davipatti/560ad735a2d531d5dddbc61dc572420e to your computer and use it in GitHub Desktop.
Increment a counter up and down in marimo.
import marimo
__generated_with = "0.11.30"
app = marimo.App(width="medium")
@app.cell
def _():
import marimo as mo
return (mo,)
@app.cell
def _(mo):
max_count = 5
get_count, set_count = mo.state(0)
return get_count, max_count, set_count
@app.cell
def _(get_count):
get_count()
return
@app.cell
def _(get_count, max_count, mo, set_count):
mo.ui.array(
[
mo.ui.button(
on_click=lambda _: set_count((get_count() - 1) % max_count), label="prev"
),
mo.ui.button(
on_click=lambda _: set_count((get_count() + 1) % max_count), label="next"
),
]
)
return
@app.cell
def _():
return
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment