I managed to temporarily resolve the issue by replacing the Select widget with a new one, here is updated working code
import panel as pn
pn.extension()
placeholder_code = '---SELECT OPTION---'
def create_select():
return pn.widgets.Select(size=10)
def create_parent_select(label_widget, code):
def get_parent_options(code):
...
options = get_parent_options(code)
parent_select = create_select()
parent_select.link(label_widget, callbacks={'value': set_label_widget})
if options == []:
parent_select.disabled = True
parent_select.options = []
else:
parent_select.options = [placeholder_code] + options
return parent_select
def create_children_select(label_widget, code):
def get_children_options(code):
...
children_select = create_select()
children_select.link(label_widget, callbacks={'value': set_label_widget})
options = get_children_options(code)
if options == []:
children_select.disabled = True
children_select.options = []
else:
children_select.options = [placeholder_code] + options
return children_select
def create_dashboard(dashboard, starting_code="root"):
if starting_code == placeholder_code:
return
dashboard.clear()
label_widget = pn.widgets.StaticText(value=starting_code)
parent_select = create_parent_select(label_widget, starting_code)
children_select = create_children_select(label_widget, starting_code)
dashboard.append(parent_select)
dashboard.append(label_widget)
dashboard.append(children_select)
return dashboard
dashboard = pn.Row()
Updating = True
create_dashboard(dashboard)
Updating = False
def set_label_widget(target, event):
global Updating
global dashboard
if Updating:
return
Updating = True
create_dashboard(dashboard, event.new)
Updating = False
dashboard.servable()
Essentially with each new option selection, I remove the old widget and create a new one with the updated options. I needed to append a place holder option, that is skipped on purpose, because otherwise it would right away callback again on the new selection of first element in widget upon creation.
For my purposes, the option lists are small and therefore it is acceptable solution for the time being.