Select widget disabled_options does not work when options is a dictionary

Hi there,

As documented here: Select Widget Doc

  • disabled_options (list): Optional list of options that are disabled, i.e. unusable and un-clickable. If options is a dictionary, the list items must be dictionary values.

However, when the values of the options dictionary are integers, the disabled_options will not work. The widget will not show up when the widget is defined as below:

import panel as pn

pn.extension()

select = pn.widgets.Select(name="Select", 
                           options={"Biology": 1, "Chemistry": 2}, 
                           disabled_options=[2])
select

Hi MuseA

Please have a look at this example. For sure, The code here is not the best example, but just for inspire you. The link, bind also may works

import panel as pn

pn.extension(comms = 'vscode')

toggle = pn.widgets.Toggle(name='Toggle', button_type='success',value = False)

@pn.depends(toggle)

def toggle_click(event):

    print(event)

    if event == True:

       

        select.disabled = True

    else:

        select.disabled = False

select = pn.widgets.Select(

    name="Select",

    options={"Biology": 1, "Chemistry": 2},

    disabled = False)

pn.Column(select,toggle,toggle_click).show()

Kind regards
Victor

Hi CongTang,

Thanks! I ended up with the similar strategy, to define a dependent function to change the widget’s disabled_options value. Would be better if the documentation can showcase a better solution.