How to implement reset button to clear output

Hi mike, hope the code below helps.
spiraf9fLe

import dash
from dash.dependencies import Input, Output
import dash_html_components as html

app = dash.Dash()
app.layout = html.Div([
    html.Div(id='output'),
    html.Button('Input',id='input_button',n_clicks=0),
    html.Button('Reset',id='reset_button', n_clicks=0),
], style={'marginTop':20, 'marginLeft':20})

@app.callback(Output('output','children'),
             [Input('input_button','n_clicks')])
def update(input_clicks):
    if input_clicks>0:
        return f'there are {input_clicks} input clicks.'

@app.callback(Output('input_button','n_clicks'),
             [Input('reset_button','n_clicks')])
def update(reset):
    return 0


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