Hi,
I want to a panel app like this but I don’t found how to do the precise action I mentioned in my comment there :
import panel as pn
NUMBER_OF_ROWS = 8
rows = pn.Column()
ui = pn.template.VanillaTemplate()
apply_button = pn.widgets.Button(name='apply', button_type='success')
ui.modal.append(
pn.Column(
pn.widgets.IntInput(),
apply_button))
def close_modal(_):
# I want that the action of closing the modal also put the value
# of the IntInput inside the str pane that is at the left of the
# button I clicked first to open the modal
ui.close_modal()
apply_button.param.watch(close_modal, "value")
def button_callback(_):
ui.open_modal()
for i in range(NUMBER_OF_ROWS):
button = pn.widgets.Button(name="click me")
rows.append(pn.Row(pn.pane.Str("default"), button))
button.param.watch(button_callback, "value")
ui.main.append(rows)
ui.show()
I wanted the “click me” buttons to be all the same, so I can’t use the “name” attribute of the button to know which button I clicked. I also know I could do an easier app with just a lot of IntInputs but in my final app using the modal like this would be important because I have to include other widgets in this “control” modal.
What if you print event? There should be event.obj.name I think.
def close_modal(event):
# I want that the action of closing the modal also put the value
# of the IntInput inside the str pane that is at the left of the
# button I clicked first to open the modal
ui.close_modal()
Yes I can print the event.obj.name but since I want all my buttons to have the same name it doesn’t help me to know which one of them triggered the modal. Is it possible to add to my button a “home made” attribute ? I could use it to store an id shared by both button and str pane of the same row in order to find which str pane I should modify when I only know the triggered button.
I finally found a way !
I got it using a lambda function that introduces a new parameter. Here’s my code if it can help someone :
(I additionnally added various str panes and buttons per row because I want my final app to look like this)