Changing the disabled function of a widget inside a function

I would like to know if it’s possible to turn on/off a widget in a responsive way. For example, in the image below, I would like to make the ‘K clusters’ widget disabled if the button ‘Inter-K’ is on. And the opposite as well

Yes, you can use the attribute constant for this:

class K(param.Parameterized):
    options = param.Selector(objects=['K Inter', 'K Intra'])
    select = param.Selector(objects=['K1', 'K2', 'K5'])
    
    @param.depends('options', watch=True)
    def disable_select(self):
        if self.options == 'K Intra':
            self.param['select'].constant = True
        else:
            self.param['select'].constant = False
    
    def panel(self):
        return pn.Param(self.param, widgets={'options': pn.widgets.RadioButtonGroup})
    
K().panel()

image

2 Likes