Skip to content
Advertisement

Do a button click from code in plotly dash

I have 3 buttons that stand side by side on my UI. When the user clicks one of them, the buttons that are standing right of the clicked button should be also clicked step by step. Is there a way to manage this scenario in plotly-dash?

To show it visually,
buttons

Advertisement

Answer

Yes. Make a callback that takes in the 1st button’s n_clicks prop, and outputs to the 2nd button’s n_clicks prop. Same for the 2nd to 3rd buttons.

A simple example:

@app.callback(Output('button-2', 'n_clicks'),
              [Input('button-1', 'n_clicks')])
def callback_func(button_clicks):
    if button_clicks:
        return button_clicks
    raise dash.exceptions.PreventUpdate
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement