# Multiple callbacks executed by a single Input change

**URL:** https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673
**Category:** Dash Python
**Created:** [June 4, 2018, 11:37am UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673 "2018-06-04T11:37:28Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![willgdjones](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/willgdjones/32/2855_2.png) [@willgdjones](https://community.plotly.com/u/willgdjones)
#### Post date: [June 4, 2018, 11:37am UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/1 "2018-06-04T11:37:28Z")

</div>

I have a Plotly application with a DatePickerRange input and a Dropdown input which power a set of dashboards.

Whenever an input is modified, I have a callback which registers this change and refreshes the data that powers the dashboard.

```
@app.callback(
    dash.dependencies.Output('time-series-figure', 'figure'),
    [dash.dependencies.Input('my-date-picker-range', 'start_date'),
    dash.dependencies.Input('my-date-picker-range', 'end_date'),
    dash.dependencies.Input('extruder-choice', 'value')]
        )
def update_daterange(startdate, enddate, extruder):
      date_range = [startdate, enddate]
      return self.refresh(date_range, extruder)

```

I noticed that this was taking more time than I expected. After placing a `pdb.set_trace()` within the function:

```
def update_daterange(startdate, enddate, extruder):
    date_range = [startdate, enddate]
    pdb.set_trace()  
    return self.refresh(date_range, extruder)

```

And inspecting my console:

```
127.0.0.1 - - [04/Jun/2018 12:03:04] "POST /_dash-update-component HTTP/1.1" 200 -
(Pdb) c
127.0.0.1 - - [04/Jun/2018 12:03:07] "POST /_dash-update-component HTTP/1.1" 200 -
(Pdb) c
127.0.0.1 - - [04/Jun/2018 12:03:09] "POST /_dash-update-component HTTP/1.1" 200 -
(Pdb) c
127.0.0.1 - - [04/Jun/2018 12:03:11] "POST /_dash-update-component HTTP/1.1" 200 -
(Pdb) c

```

I noticed that this callback was being executed **exactly 4 times**. Since I am running the server in debug mode, as the following code specifies, I am anticipating that only one request should be made.

```
dl = DataLoader(connection_config=connection_config)
dl.connect()

db = Dashboard(dl)
db.configure()

if __name__ == ' __main__':
    db.app.run_server(debug=True, port=8051)

```

This is because of the default options on `run_server`

> <https://github.com/plotly/dash/blob/master/dash/dash.py#L564-L568>

results in the default `Flask` options to be used:

> <https://github.com/pallets/flask/blob/master/flask/app.py#L940-L948>

which in turn call the Werkzeug function `run_simple`,

> <https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L736-L741>

which has the default number of processes equal to 1.

**Why is the callback executed 4 times?**

Thanks for your help!

Best,  
Will

---

<div class="post-metadata">

### Author: ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)
#### Post date: [June 4, 2018, 10:31pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/2 "2018-06-04T22:31:50Z")

</div>

> [@willgdjones](#):
>
> **Why is the callback executed 4 times?**

My guess is:

- Once on page load to initialize
- Another time when one of the inputs change
- All of that times 2 because of a recent dash-renderer bug that got fixed: [fix update behaviour for multiple properties by chriddyp · Pull Request #54 · plotly/dash-renderer · GitHub](https://github.com/plotly/dash-renderer/pull/54) and released (`dash-renderer==0.13.0`)

---

<div class="post-metadata">

### Author: ![willgdjones](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/willgdjones/32/2855_2.png) [@willgdjones](https://community.plotly.com/u/willgdjones)
#### Post date: [June 5, 2018, 10:08am UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/3 "2018-06-05T10:08:53Z")

</div>

Hi chriddyp,

I have now upgraded my version of `dash-renderer` to be `0.13.0`, but strangely enough, continue to register 4 executions of the callback. This occurs **after** the page has loaded, and so _only when one of the inputs change_.

I am reasonably confident that this is what is happening, but I am continuing to dig. Any suggestions/potential directions to follow would be greatly appreciated!

Thanks for your help as always,  
Will

---

<div class="post-metadata">

### Author: ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)
#### Post date: [June 5, 2018, 3:15pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/4 "2018-06-05T15:15:34Z")

</div>

Thanks for checking @willgdjones! This could be a bug. Could you create a really small, reproducable example that demonstrates this issue? The smaller/simpler the better.

---

<div class="post-metadata">

### Author: ![willgdjones](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/willgdjones/32/2855_2.png) [@willgdjones](https://community.plotly.com/u/willgdjones)
#### Post date: [June 6, 2018, 2:21pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/5 "2018-06-06T14:21:59Z")

</div>

Hi @chriddyp, here is a gist of a minimum viable example.

> <https://gist.github.com/willgdjones/48eb304bf603ec3e08f8245326a159e9>

Upon modifying the DateRangePicker, there are in fact **3 executions** of the callback. When I modify the Dropdown component, though, there is a single callback.

Let me know if you can reproduce this!

Versions:  
dash-html-components==0.9.0

```
plotly==2.5.1
dash==0.21.0
numpy==1.14.1
pandas==0.23.0
dash-core-components==0.21.0
dash-renderer==0.13.0
```

---

<div class="post-metadata">

### Author: ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)
#### Post date: [June 7, 2018, 4:14pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/6 "2018-06-07T16:14:50Z")

</div>

Thanks @willgdjones! checking this out now.

---

<div class="post-metadata">

### Author: ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)
#### Post date: [June 7, 2018, 4:27pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/7 "2018-06-07T16:27:21Z")

</div>

Looks like a bug in the `DatePickerRange` component. Should be an easy fix. I’ve created an issue here: [https://github.com/plotly/dash-core-components/issues/209](https://github.com/plotly/dash-core-components/issues/209)

---

<div class="post-metadata">

### Author: ![klnrdknt](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/klnrdknt/32/3758_2.png) [@klnrdknt](https://community.plotly.com/u/klnrdknt)
#### Post date: [August 1, 2018, 2:28pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/8 "2018-08-01T14:28:18Z")

</div>

I do get a similar bug when using callbacks that have multiple inputs, as in:

```auto
dynamically_generated_function = self._createCallback()
self._app.callback(
    Output(elem, 'style'),
    [Input(dropdown, 'value'),
    Input(mainInput, 'value'),
    Input(secInput, 'value')],
    [State(mainInput, 'value'),
    State(secInput, 'value')]
)(dynamically_generated_function)
```

I print out stuff in the callback function to see how many times it executes and it consistently does so 3 times even though I only change the value in one input, single digit… Is that supposed to happen?

EDIT: Also all my dash libraries are up-to-date.

---

<div class="post-metadata">

### Author: ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)
#### Post date: [August 1, 2018, 3:42pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/9 "2018-08-01T15:42:34Z")

</div>

> [@klnrdknt](#):
>
> I print out stuff in the callback function to see how many times it executes and it consistently does so 3 times even though I only change the value in one input, single digit… Is that supposed to happen?

That shouldn’t happen. Can you share a small, reproducable example?

---

<div class="post-metadata">

### Author: ![klnrdknt](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/klnrdknt/32/3758_2.png) [@klnrdknt](https://community.plotly.com/u/klnrdknt)
#### Post date: [August 1, 2018, 3:53pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/10 "2018-08-01T15:53:54Z")

</div>

I’ll try to, might have to write one specifically, as the app is huge.

---

<div class="post-metadata">

### Author: ![klnrdknt](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/klnrdknt/32/3758_2.png) [@klnrdknt](https://community.plotly.com/u/klnrdknt)
#### Post date: [August 1, 2018, 6:21pm UTC](https://community.plotly.com/t/multiple-callbacks-executed-by-a-single-input-change/10673/11 "2018-08-01T18:21:58Z")

</div>

Tried to reproduce, fixed instead it seems. 😢
