I'm having a lot of trouble with placing
I'm having a lot of trouble with placing a button in an
accordion
element. For example,
works, however,
does not. Can anyone please explain to me the difference, and how to make a function that returns a button, and is lazy-evaluated?16 Replies
This seems like a bug with the button not being registered as UI element when being lazily rendered
is it possible to move the button out of the expensive evaluation?
So my actual code looks more like:
because I don't know how many buttons I'll need before the cell runs (10 for the sake of example, but it's variable)
Would this work in the mean time?
yea that seems totally fine - (if you update to
f"Reveal Button {idx}"
).
if its not buttons (i.e checkbox) and you need to depend on the actual value (instead of the using callback)
you can also do buttons = mo.ui.array([mo.ui.button() for idx in range(10)])
and then index into the buttons
like you would a normal arrayThank you @Myles Scolnick !
Is this an issue with
_clone
?I’m not entirely sure the issue - @Akshay would know better.
I would’ve guess it’s because the ui element is not registered as a global, but I’m pretty sure it’s the same case in your working example
Thanks, still trying to wrap my head around the globals thing. I keep repeating, "think Excel, think Excel ..."
I still get tripped up from time to time
UI elements get registered when they’re instantiated, and I wouldn’t have guessed that lazy evaluation would interfere with that. But it could! I’m out today but can check tomorrow.
Curious to know if it only affects buttons or all
UIElement
s, I haven't triedIt’d be all ui elements
Yeah, makes sense
Initially I made the mo.lazy to be FE lazy. Then when I made it BE lazy, I probably didn’t add support for UI elements (hence needing to create the buttons beforehand)
One more thing about
accordion
: The docs say. [lazy] is a convenience that wraps each accordion in a mo.lazy component.
mo.lazy
takes an arg show_loading_indicator
. Would it make sense to add the show_loading_indicator
to accordion
have have it pass through to mo.lazy
?
Now that I think about it, if mo.lazy
is a wrapper around accordion
, then accordion
can't pass args to its own wrapper ...we could add the
show_loading_indicator
to mo.accordion args as well (to pass when it uses lazy under the hood. you can probably roll it yourself at the cost of some extra code
Oh I see,
lazy
wraps the callable, not the accordion, got it. Thanks!
Would you like me to submit an issue for this in the repo?yes, please! that would be appreciated