I have a dropdown menu and a button as follows:
import panel as pn
pn.extension()
select = pn.widgets.Select(options=["a", "b", "c"])
button = pn.widgets.Button(name='Confirm selection')
def add(event):
choice = select.value
return choice
selection = pn.bind(add, button)
panel = pn.WidgetBox(pn.Column(
select,
button,
selection,
))
panel
I can show the most recent selection in a panel by using selection
or access this value in python using selection()
.
The panel looks like this:
However, I now want to extend this code such that I can concatenate results. I tried the following code:
name = ""
def calculateTotal(event):
name += selection()
return name
button.on_click(calculateTotal)
But this generates the error: UnboundLocalError: local variable 'name' referenced before assignment