🐠
🐠
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
(I didn't get a notification so didn't see the response till now!!)
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
Thank you!!
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
It worked! Hallelujah thank you so much! I don’t fully understand the code though… is this making the dictionary of buttons twice?
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
Thanks! @Akshay . Out now and will take a look soon. Thank you for looking into this so promptly!
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
Hi @Akshay and @Myles Scolnick , thanks a lot for the followups; I haven't been able to fully dedicate time to this button issue. It turns out I had a hack it seems... and it's still not ideal. I am wondering if for the following use case, what I have is the only way. Use case: I want to create a vertical stack of N buttons, where N can vary. Each button is supposed to initiate an action according to the index of the button in the N-array. In addition, I prefer not to see "dictionary" or "array". What I have right now:
# cell 1
N=5
get_x, set_x = mo.state(-1)

# cell 2
def button_i(val):
set_x(val)
return (val-1)

# cell 3
buttons_dict = mo.ui.dictionary([
f'button_{i}': mo.ui.button(value=i, label=f'test', on_click = lambda v: button_i(v) for i in range(N)
])

# cell 4
mo.vstack([
buttons_dict.elements[k] for k in buttons_dict.value.keys()
])

# cell 5
buttons_dict
# cell 1
N=5
get_x, set_x = mo.state(-1)

# cell 2
def button_i(val):
set_x(val)
return (val-1)

# cell 3
buttons_dict = mo.ui.dictionary([
f'button_{i}': mo.ui.button(value=i, label=f'test', on_click = lambda v: button_i(v) for i in range(N)
])

# cell 4
mo.vstack([
buttons_dict.elements[k] for k in buttons_dict.value.keys()
])

# cell 5
buttons_dict
The look I'd like is in # cell 4 and not # cell 5 but unfortunately the reactivity in get_x() does not work if I only have # cell 4 without cell 5... I have tried `mo.ui.batch suggested but I could not get the dynamic change of the number of buttons according to N work. Is there something else I can try, or modify? Thank you!
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
Oh odd… it works now
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
Hi! I have a follow up question - I want to display my_dict without showing the key and dictionary view. What I can manage is mo.vstack([my_dict.elements[k] for k in my_dict.value.keys()]). But that seems to have disabled the button on_click functionality. Is there a way to do that? I wonder if it’s scope issue again. Sorry typing on the phone so not writing the code view properly.
15 replies
Mmarimo
Created by 🐠 on 11/15/2023 in #archived-help-and-support
Creating a list of buttons
Thanks, Myles! Dictionary worked. Thanks so much life is beautiful again 🀩🀩 definitely missed that in the documentation and should have thought of global scope.
15 replies