How to use @app.callback as to return DropDown to be enabled

and this is my code

import dash
from dash.dependencies import Input, Output
import dash_table
import dash_core_components as dcc
import dash_html_components as html
from myPandas import site_code_col, exting_sites, ext_sites


app = dash.Dash(__name__)

app.layout = html.Div([

    dcc.Markdown('''
        >** From PP to Optimization**
        '''),
    # html.Label('From PP to Optimization'),
    dcc.Checklist(
        options=[
            {'label': 'From HU PP to HU Opt.', 'value': 'HPPO'}
        ],
        labelStyle={
            'display': 'inline-block',
            'margin-right': 50
        },
        id='frmHPPTHOpt'
    ),

    dcc.Markdown('''
    ** Choose Sites which depends on PP(Review PP Report (FirstTime))**
    '''),
    dcc.Checklist(
        options=[
            {'label': 'Review PP Report (FirstTime)', 'value': 'RPRFT', 'disabled': True},
        ],
id='rvpprptft'
    ),
    # html.Label('Choose Sites which depends on PP(Review PP Report (FirstTime))'),
    dcc.Dropdown(
        id="scRPRFT",
        options=[{'label': i['site_code'], 'value': i['site_code']} for i in site_code_col],
        placeholder="Select a SiteCode",
        multi=True,
        disabled=True
        #        value="MTL"
    ),

    dcc.Markdown('''
    ** Choose Sites which depends on PP(Review PP Report (Rectified from TE Plan))**
    '''),
    dcc.Checklist(
        options=[
            {'label': 'Review PP Report (Rectified from TE Plan)', 'value': 'RPRRTP', 'disabled': True},
        ],
    ),
    # html.Label('Choose Sites which depends on PP(Review PP Report (Rectified from TE Plan))'),
    dcc.Dropdown(
        id="scRPRRTP",
        options=[{'label': i['site_code'], 'value': i['site_code']} for i in site_code_col],
        placeholder="Select a SiteCode",
        multi=True,
        disabled=True
        #        value="MTL"
    ),

    dcc.Markdown('''
    ** Choose Sites which depends on PP(Review PP Report (Rectified from TE Opt.))**
    '''),
    dcc.Checklist(
        options=[
            {'label': 'Review PP Report (Rectified from TE Opt.)', 'value': 'RPRTO', 'disabled': True},
        ],
    ),
    # html.Label('Choose Sites which depends on PP(Review PP Report (Rectified from TE Opt.))'),
    dcc.Dropdown(
        id="scRPRRTO",
        options=[{'label': i['site_code'], 'value': i['site_code']} for i in site_code_col],
        placeholder="Select a SiteCode",
        multi=True,
        disabled=True
        #        value="MTL"
    ),

    dcc.Markdown('''
    ** Choose Sites which depends on PP(Review PP Report (Rectified from TE Opt. & Plan)))**
    '''),
    # html.Label('Choose Sites which depends on PP(Review PP Report (Rectified from TE Opt. & Plan))'),
    dcc.Checklist(
        options=[
            {'label': 'Review PP Report (Rectified from TE Opt. & Plan)', 'value': 'RPRRTOP', 'disabled': True},
        ],
    ),
    dcc.Dropdown(
        id="scRPRRTOP",
        options=[{'label': i['site_code'], 'value': i['site_code']} for i in site_code_col],
        placeholder="Select a SiteCode",
        multi=True,
        disabled=True
        #        value="MTL"
    ),

    html.Button('Submit', id='button'),
    html.Div(id='datatable-row-ids-container')
])

if __name__ == '__main__':
    app.run_server(debug=True)

Now All I need when I click the checkbox with this id='rvpprptft', Just make the other the Dropdown enable

#Edited
I tried Something like this but it doesn’t work

@app.callback(
    Output('scRPRFT', 'options'),
    [Input('rvpprptft', 'value')])
def set_PP_HUOpt_cb_enable(hu_pp_opt_checked_list):
    return [{'disabled':False, 'value': i} for i in ext_sites[hu_pp_opt_checked_list]]

and this error I found

Callback error updating scRPRFT.options

and I tired this also

@app.callback(
    Output('scRPRFT', disabled=False),
    [Input('rvpprptft', 'value')])
def set_PP_HUOpt_cb_enable(hu_pp_opt_checked_list):
    return [{'disabled':False, 'value': i} for i in ext_sites[hu_pp_opt_checked_list]]

and this is error I found

Traceback (most recent call last):
  File "C:/Users/DELL/PycharmProjects/Gov-Trac-Tool/jhfjfgh.py", line 167, in <module>
    Output('scRPRFT', disabled=False),
TypeError: __init__() got an unexpected keyword argument 'disabled'

#Edited 2
I tried some thing like this

@app.callback(
    Output('scRPRFT', 'disabled'),
    [Input('rvpprptft', 'value')])
def set_PP_HUOpt_cb_enable():
    return [{'disabled':False}]

and this is the error for the previous part

Callback error updating scRPRFT.disabled

but it doesn’t work also

I tried this also find the same error

@app.callback(
    Output('scRPRFT', 'disabled'),
    [Input('rvpprptft', 'value')])
def set_PP_HUOpt_cb_enable():
    return dcc.Dropdown(disabled=False)

this is the last updated code

any one have any idea for the right syntax to do this?

The following will set the disabled property to False regardless of the input. For each input or state, you need a parameter named in your function defition. You might want other inputs into this funtion should you want to re-enable the dropdown.

@app.callback(
    Output('scRPRFT', 'disabled'),
    [Input('rvpprptft', 'value')])
def set_PP_HUOpt_cb_enable(val):
    return False
2 Likes

Thanks for your support but actually, what I need when click checklist item just return dropdown item to False, this code just return False only

Create a div where the dropdown would go, and id that to rvpprptft. Then, create a callback that returns the entire dropdown, and make the input the value of rvpprptft:

@app.callback(
    Output('scRPRFT', 'children'),
    [Input('rvpprptft', 'value')])
def set_PP_HUOpt_cb_enable(val):
    if val == True:
        return dcc.Dropdown(disabled=False)
    else:
        return dcc.Dropdown(disabled=True)

I think this is the right way but I find this error Here are the available properties in "scRPRFT": ['id', 'options', 'value', 'optionHeight', 'className', 'clearable', 'disabled', 'multi', 'placeholder', 'searchable', 'style', 'loading_state'] as the children is not the available properties, I tried to add disabled but doen’t work also :frowning:

Those are the properties of the Dropdown, not the Div I suggested to frame the Dropdown in. What you should in theory be doing is this: have a Div, then replace its contents (children) depending on your checkbox, with either a disabled or an enabled Dropdown.