[Python] Change dash Checklist values by callback

Discussão em 'Python' iniciado por Stack, Julho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to change the selected options of an plotly dash checklist by an callback. My minimal working example is as following (Values should change by hitting the 'load' button -> at loading the page nothing ist selected, after click the button 'SF' should be selected):

    import dash

    app = dash.Dash(__name__)

    app.layout = html.Div([

    dcc.Checklist(
    options=[
    {'label': 'New York City', 'value': 'NYC'},
    {'label': 'Montréal', 'value': 'MTL'},
    {'label': 'San Francisco', 'value': 'SF'}
    ],
    labelStyle={'display': 'block'},
    value=[]
    ),

    html.Button('load', id='load-button', n_clicks=0)
    ])

    @app.callback(Output('checkliste', 'value'),
    Input('load-button', 'n_clicks'))
    def change_values(n_clicks):
    if n_clicks > 1:
    return ['SF']



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

    Continue reading...

Compartilhe esta Página