How to check whether a button is clicked or not?

I have a very simple question of button event. I just want to know how to check whether a button is click or not in callback. Yes, we can check how many times a button is clicked. But i want to know whether we can check the click event or not.

Example -

html.Button('Click Me', id='button')

@app.callback(Output('----','----'),
                     [Input('button','n_clicks'),
                      Input('----','-----')
                       Input('-----','-------')])
 def clickevent(n_clicks):
     if **button clicked**:
         do this
     
     do this

There are number of inputs in which button input also. If button is click i want to do some extra stuff.Is it possible to check whether a button is click or not.

Thanks :slight_smile:

without knowing what other inputs are in this callback, you could use a dcc.Store to keep track of the n_click_timestamp assoc. with this button. Pass this value in as a State along with the button’s n_click_timestamp. Comparing timestamps would allow you to determine if the button was pressed vs reaching this callback from the other inputs.

If the other inputs to this callback also have a n_click_timestamp parameter, you can compare the timestamps themselves w/o the need for a dcc.Store

Hi, you can use dash.callback_context. see FAQ. :slightly_smiling_face: