Get help from the marimo community

Updated 6 months ago

Creating a UI component that can update itself

I want to create a batch element, where a drop-down lets the user configure the content of the batch elements, such as having additional features revealed if choosing to do so by the user. For that to work, I need to re-run the cell that generates the batch element. Is there a method to re-run the same cell? I was thinking I could use states to trigger this, but if states are set from the same cell, they dont trigger an update. I couldn't find any documentation about this type of reactivity, as it seems cells can only trigger other cells and not themselves.
A
2 comments
Yea, use allow_self_loops=True in the mo.state constructor.

Plain Text
import marimo

__generated_with = "0.7.0"
app = marimo.App(width="medium")


@app.cell
def __():
    import marimo as mo
    return mo,


@app.cell
def __(mo):
    get_state, set_state = mo.state(0, allow_self_loops=True)
    return get_state, set_state


@app.cell
def __(get_state, set_state):
    if (i := get_state()) < 10:
        print(i)
        set_state(lambda v: v + 1)
    return i,


if __name__ == "__main__":
    app.run()
Add a reply
Sign up and join the conversation on Discord