Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactivity lost when UI items are inside list/dict #3798

Closed
imagejan opened this issue Feb 14, 2025 · 1 comment
Closed

Reactivity lost when UI items are inside list/dict #3798

imagejan opened this issue Feb 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@imagejan
Copy link

Describe the bug

I'd like to dynamically change the number of input widgets (here: radio button groups) by putting them inside a list or dict.

While the display of radio button groups in a mo.hstack works fine and adjusts to the user-defined number, updating the selected radio-button values doesn't trigger re-running of the subsequent cells.

I guess that's explainable because the list/dict objects themselves don't change, but is there a simple way to restore reactivity for the case of UI elements nested in lists?

Environment

{
  "marimo": "0.11.4",
  "OS": "Windows",
  "OS Version": "10",
  "Processor": "Intel64 Family 6 Model 165 Stepping 2, GenuineIntel",
  "Python Version": "3.12.7",
  "Binaries": {
    "Browser": "133.0.6943.60",
    "Node": "--"
  },
  "Dependencies": {
    "click": "8.1.7",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.1",
    "markdown": "3.7",
    "narwhals": "1.22.0",
    "packaging": "24.1",
    "psutil": "6.1.0",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.14.3",
    "pyyaml": "6.0.2",
    "ruff": "0.9.6",
    "starlette": "0.45.3",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.34.0",
    "websockets": "14.2"
  },
  "Optional Dependencies": {
    "altair": "5.5.0",
    "pandas": "2.2.3",
    "pyarrow": "19.0.0"
  },
  "Experimental Flags": {}
}

Code to reproduce

Here's a minimal example:

import marimo

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


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


@app.cell
def _(mo):
    num_categories = mo.ui.slider(start=1, stop=5)
    num_categories
    return (num_categories,)


@app.cell
def _(mo, num_categories):
    selections = {}
    for _c in range(num_categories.value):
        selections[_c] = mo.ui.radio(["1", "2", "3"])
    return (selections,)


@app.cell
def _(mo, selections):
    mo.hstack([_select for _, _select in selections.items()], justify="start")
    return


@app.cell
def _(selections):
    [_s.value for _, _s in selections.items()]
    return


@app.cell
def _(mo, num_categories):
    selections_list = []
    for _ in range(num_categories.value):
        selections_list.append(mo.ui.radio(["1", "2", "3"]))
    return (selections_list,)


@app.cell
def _(mo, selections_list):
    mo.hstack(selections_list, justify="start")
    return


@app.cell
def _(selections_list):
    [_s.value for _s in selections_list]
    return


@app.cell
def _():
    return


if __name__ == "__main__":
    app.run()

Try selecting some of the radio buttons and observe that the subsequent cells don't update.

@imagejan imagejan added the bug Something isn't working label Feb 14, 2025
@imagejan
Copy link
Author

Sorry, I should have read the documentation in more detail.

The intended way to solve this is by using mo.ui.array().

Closing this, sorry for the buzz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant