Panel select widget value and display not synced

Hello,

I have come across an issue while using panel select widgets. I have two widgets, one to select a subject and one to select a valid run for that subject. Not all of the subjects have the same number of runs so I have to make a function where the run selecting widget’s output and value change given a selected subject. The way I have my widget designed is that when a new subject is selected, if the run value of the old subject is a valid run value of the new subject (in the list of runs for the new subject), then the run select value doesn’t change. If the run value is not a valid run for the newly selected subject, then the run value is the first run value of the list of runs for the new subject. An example of my code is given below:

import panel as pn
pn.extension('plotly')

data_info = {'sub01':['run1','run2','run3','run4'],'sub02':['run1','run3','run4'],'sub03':['run1','run2'],'sub04':['run1','run2','run3','run4']}
subject_list = list(data_info.keys())

sub_sel = pn.widgets.Select(name='Select Subject', options=subject_list, value=subject_list[0])
run_sel = pn.widgets.Select(name='Select Run', options=data_info[sub_sel.value],value=data_info[sub_sel.value][0])

@pn.depends(sub_sel.param.value,watch=True)
def update_run(SBJ):
    pre_select_val = run_sel.value
    runs = data_info[SBJ] 
    if pre_select_val not in runs:
        run_sel.value = runs[0]
        run_sel.options = runs
    else:
        run_sel.value = pre_select_val
        run_sel.options = runs

@pn.depends(run_sel.param.value)
def diplay_run_val(RUN):
    return pn.pane.Markdown("Run Value: "+RUN)
    
pn.Column(pn.Row(sub_sel,run_sel),diplay_run_val)

I have noticed that when I pick a new subject with a different number of runs then the last, but the run that is selected is a valid run for both subjects, the value of the run select widget is the same but what is actually displayed on the widget is the first run option for the new subject. A video of what I am describing is given below:

If you have any ideas as to what I might be doing wrong or any solutions I would greatly appreciate it.

Thank you!

Recipe to recreate:

  • select sub02
  • select run3
  • select sub04
    -> The Markdown display changes to run3 but the select widget changes to run1 instead of run3 as expected. If you query run_sel.value it returns run3. If you redisplay the run_sel widget, it shows run3.

This look like a bug to me. @philippjfr?

I think it’s corrected in last panel version: