# html.Button as an out target in a callback

**URL:** <https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643>\
**Category:** Dash Python\
**Created:** [November 14, 2018, 3:50pm UTC](https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643 "2018-11-14T15:50:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steelhead](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@steelhead](https://community.plotly.com/u/steelhead)\
**Post date:** [November 14, 2018, 3:50pm UTC](https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643/1 "2018-11-14T15:50:31Z")

</div>

I’m trying to determine if a button can be the output target of a callback, that is, use the  
callback output to fire the button to ‘click’?

For example, I’d like the button with id=‘target-button-id’ to be ‘clicked’ id the date-picker-range value(s) change:

```
@app.callback(
        dash.dependencies.Output('target-button-id', '<some-button-attribute>'),
        [dash.dependencies.Input('date-picker-range', 'start_date'),
         dash.dependencies.Input('date-picker-range', 'end_date')]
    )
    def click_button_if_date_changed(start_date, end_date):
        return <something-to-click-button>
```

---

<div class="post-metadata">

**Author:** ![mikesmith1611](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/mikesmith1611/32/2130_2.png) [@mikesmith1611](https://community.plotly.com/u/mikesmith1611)\
**Post date:** [November 14, 2018, 4:07pm UTC](https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643/2 "2018-11-14T16:07:06Z")

</div>

You could try increasing the n\_clicks attribute of the button?

---

<div class="post-metadata">

**Author:** ![steelhead](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@steelhead](https://community.plotly.com/u/steelhead)\
**Post date:** [November 14, 2018, 5:34pm UTC](https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643/3 "2018-11-14T17:34:10Z")

</div>

Mike - thanks much for the suggestion. I have a follow-up question: how do you get the attributes, in this case, n\_clicks, when the button is not in the input? That is, what is the return value if you don’t already know what n\_clicks is equal to?

---

<div class="post-metadata">

**Author:** ![mikesmith1611](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/mikesmith1611/32/2130_2.png) [@mikesmith1611](https://community.plotly.com/u/mikesmith1611)\
**Post date:** [November 14, 2018, 5:38pm UTC](https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643/5 "2018-11-14T17:38:37Z")

</div>

You can use State as an input:

@app.callback(  
dash.dependencies.Output(‘target-button-id’, ‘n\_clicks’),  
[dash.dependencies.Input(‘date-picker-range’, ‘start\_date’),  
dash.dependencies.Input(‘date-picker-range’, ‘end\_date’)],  
[dash.dependencies.State((‘target-button-id’, ‘n\_clicks’)]  
)  
def click\_button\_if\_date\_changed(start\_date, end\_date, old\_n\_clicks):  
return old\_n\_clicks + 1

This will of course only work if you have a second callback that takes (‘target-button-id’, ‘n\_clicks’) as an input to do something else.

---

<div class="post-metadata">

**Author:** ![steelhead](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@steelhead](https://community.plotly.com/u/steelhead)\
**Post date:** [November 14, 2018, 5:59pm UTC](https://community.plotly.com/t/html-button-as-an-out-target-in-a-callback/15643/6 "2018-11-14T17:59:52Z")

</div>

Spot on answer Mike! Thank you.
