How to disable a RadioItems component

Hello,
I’m trying to disable a RadioItems component in my code but there is no ‘disabled’ option in it
my code (simplified) :

dcc.RadioItems(
    ['New York City', 'Montréal', 'San Francisco'],
    ['New York City', 'Montréal'],
    inline = True,
    disabled = False,
    id="radio-item-defaut"
)
@app.callback(
    Output('radio-item-defaut', 'disabled'),
    Input('radio-item-defaut', 'value')
def theFunction(param):
    var_disable = True
    return var_disable

And I have this error in my shell

TypeError: The `dcc.RadioItems` component (version 2.4.1) with the ID "radio-item-defaut" received an unexpected keyword argument: `disabled`
Allowed arguments: className, id, inline, inputClassName, inputStyle, labelClassName, labelStyle, loading_state, options, persisted_props, persistence, persistence_type, style, value

So do you have an idea to resolve this problem ?

Hi @GuillaumeL,

The solution is to use the options argument of radio items, passing in disabled to whichever entries you want.

dcc.RadioItems(
        options=[
            {'label': 'New York City', 'value': 'New York City', 'disabled': True},
            {'label': 'Montreal', 'value': 'Montreal'},
            {'label': 'San Francisco', 'value': 'San Francisco'},
        ],
        value='Montreal'
    )

You can read more about the input arguments to RadioItems here!

3 Likes

Thanks 3d65. Is it possible to disable all items by default, then later I use one callback to enable all items by setting disabled=True to this radio item ID? Currently, I don’t have disabled=True for each item inside options. so by default, they are all enabled. How to do opposite way? Thanks

1 Like