I need the button name for my Holoviz Panel callback method because the name serves also as a key to a dictionary containing sql commands to be executed on click. I’ve tried to search if the event passed to the callback could have some properties including the name but I have found nothing. There must(?) be a way of identifying the button which has been clicked. Could someone help me out with this? The format below works in Jupyter Lab except for the name extraction.
class Query:
def __init__(self):
self.buttons = [btn_0, btn_1, btn_2]
self.data = dict
def callback(self, event):
value = self.dict[button_name]
# Run an SQL query using the value
return (the query result)
def bind_buttons(self):
for button in self.buttons:
pn.bind(callback, self.button, watch=True)
query = Query()
query.bind_buttons()
query_buttons = pn.Column(
'# Queries',
query.buttons[0],
query.buttons[1],
query.buttons[2],
)
In Panel, when you bind a callback to a button, the function you bind to the button does not receive any arguments by default. However, you can use a
functools.partial
function to pass additional arguments to the callback.