I think I'm encountering a bug where mo.
I think I'm encountering a bug where mo.ui.button on_click does not work inside a vstack. Anyone have any suggestions for what I'm missing? Details in thread
20 Replies
Details below
It’s not quite a bug but just a slight gotcha of our static analysis
You need to declare the button outside of the vstack first
(Is my guess without seeing the code)
Yup, that fixed it
def _on_click(value):
print('in _on_click')
_button = mo.ui.button(label="Test", on_click=_on_click)
_element = mo.vstack([_button])
_element
Thank you
Ok, now that I'm applying this to my actual marimo app, I'm wondering if it's possible to create buttons programmatically within a loop
Psuedocode:
yea you can use mo.ui.array which implements the methods of an array
(I updated the code)
I'll give mo.ui.array a go
mo.ui.array works!
But it doesn't look great for "user-facing" product
Is there a version that doesn't show the array and the collapse?
you can index into it like a normal array or use a fluid api to hstack or vstack it
I don't know what you mean by a fluid API, but it doesn't work with a vstack. In the following example, only the last button works
But it does with work with mo.ui.array
Hmm that is likely a bug
Would it be useful for me to open a GH issue?
Yes that would be great
GitHub
Button on_clicks created within a loop do not work within vstack · ...
Describe the bug When creating a dynamic number of buttons within a vstack in a loop, only the last button's on_click behavior actually works. Environment { "marimo": "0.2.8"...
Jc, what happens when you inline the button instead of a variable
None of the buttons worked when I inlined them inside the vstack a la elements.append(mo.ui.button())`
Sorry I meant the variable in the append
I'm sorry, I'm not sure I understand
No worries, I can try it out from you but report
Thanks for making the issue Chandler. This in fact isn't a bug, though I understand why it may be surprising. I have left a response that includes a 1-line fix that makes your second example work (and explains why your code wasn't working). Hope it's helpful, let me know if you have follow-up questions.
https://github.com/marimo-team/marimo/issues/929#issuecomment-1989010631
GitHub
Button on_clicks created within a loop do not work within vstack · ...
Describe the bug When creating a dynamic number of buttons within a vstack in a loop, only the last button's on_click behavior actually works. Environment { "marimo": "0.2.8"...
Thanks @Akshay ! Responded in the github issue. Appreciate the response 🙏