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
results in the default Flask
options to be used:
which in turn call the Werkzeug function run_simple
,
which has the default number of processes equal to 1.
Why is the callback executed 4 times?
Thanks for your help!
Best,
Will