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

Buttons don't get executed #3033

Closed
SpielerNogard opened this issue Dec 3, 2024 · 2 comments
Closed

Buttons don't get executed #3033

SpielerNogard opened this issue Dec 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@SpielerNogard
Copy link

SpielerNogard commented Dec 3, 2024

Describe the bug

When nesting a button in another component (like a stack) the button don't seem to work.

Environment

{
  "marimo": "0.9.27",
  "OS": "Darwin",
  "OS Version": "24.1.0",
  "Processor": "arm",
  "Python Version": "3.12.7",
  "Binaries": {
    "Browser": "131.0.6778.86",
    "Node": "v22.9.0"
  },
  "Dependencies": {
    "click": "8.1.7",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.7",
    "narwhals": "1.14.2",
    "packaging": "24.2",
    "psutil": "6.1.0",
    "pygments": "2.18.0",
    "pymdown-extensions": "10.12",
    "pyyaml": "6.0.2",
    "ruff": "0.8.1",
    "starlette": "0.41.3",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.32.1",
    "websockets": "14.1"
  },
  "Optional Dependencies": {
    "altair": "5.5.0",
    "pandas": "2.2.3",
    "pyarrow": "18.1.0"
  }
}

Code to reproduce

import marimo as mo
query_params = mo.query_params()

function_name = 'my-test-function'
mo.vstack(
        [
            mo.ui.button(
                value="dashboard",
                on_click=lambda *args, **kwargs: query_params.set("site", "dashboard"),
            ),
            mo.md(f"#### {function_name}"),
        ]
    )
@SpielerNogard SpielerNogard added the bug Something isn't working label Dec 3, 2024
@mscolnick
Copy link
Contributor

@SpielerNogard, the button cannot be inlined, and instead needs to be part of the global scope, since it is a UI element.

my_button = mo.ui.button(
    value="dashboard",
    on_click=lambda *args, **kwargs: query_params.set("site", "dashboard"),
)
mo.vstack(
    [
       my_button,
        mo.md(f"#### {function_name}"),
    ]
)

This FAQ briefly touches on it: https://docs.marimo.io/faq.html#why-aren-t-my-on-change-on-click-handlers-being-called

@akshayka
Copy link
Contributor

akshayka commented Dec 4, 2024

If this was motivated by creating a dynamic number of buttons, that works to using mo.array(), which you can then insert in a vstack.

Example: https://marimo.app/l/23fkql

Closing as this is not a bug, but feel free to ask follow up usage questions in our Discord.

@akshayka akshayka closed this as completed Dec 4, 2024
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

3 participants