import panel as pn
pn.extension()
UPDATING = False
def callback_(*events):
global UPDATING
if UPDATING:
return
print(events)
UPDATING = True
for event in events:
if event.name == 'value':
res = [int(i) for i in event.obj.options[1:]]
res = ['----'] + [str(i + 1) for i in res]
event.obj.options = res
UPDATING = False
toggle = pn.widgets.Select(name='Select', options=['----', '1', '2', '3', '4'])
dashboard = pn.Row(
toggle
)
watcher = toggle.param.watch(callback_, ['value'])
dashboard
If I select 1 in the options, I get a ValueError exception ValueError: 1 not in list
This ValueError only occurs if I select the first value after ‘----’. At beginning if I select 1, the new list changes to [‘----’, ‘2’, ‘3’, ‘4’, ‘5’] and ‘1’ is no longer in it.