Black Lives Matter. Please consider donating to Black Girls Code today.

Callback keeps firing unexpectedly

My Dash app has a callback that calls a function and returns a updated figure based on sliders and a button click. The function takes about 1 minute to run. For some reason, before the function is complete, the callback will fire again, starting the process over. Could there be some sort of timer that is trying the callback again? If so, can this timer be turned off?

Here is an example of the callback that activates from a button. This updates a figure object:

@app.callback(dash.dependencies.Output('graph_01', 'figure'),
[dash.dependencies.Input('button_01', 'n_clicks')],
              [dash.dependencies.State('slider_01', 'value'), 
               dash.dependencies.State('slider_02', 'value'),
               dash.dependencies.State('slider_03', 'value'),
               dash.dependencies.State('slider_04', 'value')])
def update_output(n_clicks, value1, value2, value4, value3):
    print(f"you've clicked {n_clicks} times")
    def_scenario(value1, value2, value4, value3)
    return make_fig(get_results()['c0_1_sd_shift'])

app.run_server(debug=False)

The process will start, but the call back will fire before it’s over. It still prints “0 clicks”, so I’m not sure what’s prompting the callback. Here is example log information:

* Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
2019-11-25 23:17:06,647 - werkzeug - INFO -  * Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
2019-11-25 23:17:11,644 - werkzeug - INFO - 127.0.0.1 - - [25/Nov/2019 23:17:11] "GET /cf/ HTTP/1.1" 200 -
2019-11-25 23:17:14,797 - werkzeug - INFO - 127.0.0.1 - - [25/Nov/2019 23:17:14] "GET /cf/_dash-layout HTTP/1.1" 200 -
2019-11-25 23:17:14,826 - werkzeug - INFO - 127.0.0.1 - - [25/Nov/2019 23:17:14] "GET /cf/_dash-dependencies HTTP/1.1" 200 -
you've clicked 0 times
2019-11-25 23:17:15,707 - kedro.io.data_catalog - INFO - Loading data from `parameters` (MemoryDataSet)...
2019-11-25 23:17:19,778 - root - INFO - Estimating target variable change_diy_tnx_cnt using model
100%|██████████| 3000/3000 [00:07<00:00, 406.07it/s]
2019-11-25 23:17:29,320 - root - INFO - Estimating target variable change_diy_tnx_cnt using model
 63%|██████▎   | 1880/3000 [00:04<00:02, 413.40it/s]
you've clicked 0 times
2019-11-25 23:17:36,529 - kedro.io.data_catalog - INFO - Loading data from `parameters` (MemoryDataSet)...
 64%|██████▍   | 1922/3000 [00:05<00:11, 95.56it/s] 
...

It get’s stuck in a loop of continual callbacks and never finishes. Does anyone else have this issue?

Hum this should not happen. All callbacks get executed when the app is launched but then they should execute only when one of the input is changed. Could you run the same with debug=True and post here the graph of callbacks (from the dev tools, you need debug=True for this). Also, which version of dash are you using?

I’m not sure what the debugger is telling me. With debug=True, I’m getting the same repeated callbacks:

Running on http://127.0.0.1:8050/cf/
2019-11-26 05:15:08,088 - __main__ - INFO - Running on http://127.0.0.1:8050/cf/
Debugger PIN: 805-424-794
2019-11-26 05:15:08,088 - __main__ - INFO - Debugger PIN: 805-424-794
you've clicked 0 times
2019-11-26 05:15:29,810 - kedro.io.data_catalog - INFO - Loading data from `parameters` (MemoryDataSet)...
2019-11-26 05:15:30,185 - kedro.io.data_catalog - INFO - Loading data from `model_input_test_filtered` (ParquetLocalDataSet)...
2019-11-26 05:15:30,573 - kedro.io.data_catalog - INFO - Loading data from `model_input_test` (ParquetLocalDataSet)...
2019-11-26 05:15:30,957 - kedro.io.data_catalog - INFO - Loading data from `fitted_scaler` (PickleLocalDataSet)...
2019-11-26 05:15:31,327 - kedro.io.data_catalog - INFO - Loading data from `numeric_summary_stats` (PickleLocalDataSet)...
2019-11-26 05:15:31,703 - kedro.io.data_catalog - INFO - Loading data from `ordinal_summary_stats` (PickleLocalDataSet)...
2019-11-26 05:15:32,082 - kedro.io.data_catalog - INFO - Loading data from `computed_mcmc_model` (PickleLocalDataSet)...
2019-11-26 05:15:32,576 - kedro.io.data_catalog - INFO - Loading data from `model_results_df` (CSVLocalDataSet)...
2019-11-26 05:15:32,580 - root - INFO - Applying complete shift policy for cluster 0, scenario: ['c0_1_sd_shift', [0], True, False, [0, 0, 0, 0], ['aap_cnt_in_20m', 'auto_service_and_maintenance_500', 'change_autozone_cnt_in_5m', 'change_family_dollar_cnt_in_5m']]
2019-11-26 05:15:32,581 - root - INFO - Estimating target variable change_diy_tnx_cnt using model
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3000/3000 [00:07<00:00, 379.49it/s]
2019-11-26 05:15:43,194 - root - INFO - Creating intervention table for features ['aap_cnt_in_20m', 'auto_service_and_maintenance_500', 'change_autozone_cnt_in_5m', 'change_family_dollar_cnt_in_5m'] using sd
2019-11-26 05:15:43,198 - root - INFO - Feature aap_cnt_in_20m: standardized value 0, true value 0.0
2019-11-26 05:15:43,199 - root - INFO - Feature auto_service_and_maintenance_500: standardized value 0, true value 0.0
2019-11-26 05:15:43,200 - root - INFO - Feature change_autozone_cnt_in_5m: standardized value 0, true value 0.0
2019-11-26 05:15:43,201 - root - INFO - Feature change_family_dollar_cnt_in_5m: standardized value 0, true value 0.0
2019-11-26 05:15:43,201 - root - INFO - Estimating target variable change_diy_tnx_cnt using model
 57%|████████████████████████████████████████████████████████████████████████████████████████████                                                                    | 1725/3000 [00:04<00:03, 390.55it/s]you've clicked 0 times
2019-11-26 05:15:50,528 - kedro.io.data_catalog - INFO - Loading data from `parameters` (MemoryDataSet)...
 59%|██████████████████████████████████████████████████████████████████████████████████████████████▏                                                                 | 1765/3000 [00:05<00:06, 180.00it/s]2019-11-26 05:15:50,945 - kedro.io.data_catalog - INFO - Loading data from `model_input_test_filtered` (ParquetLocalDataSet)...
2019-11-26 05:15:51,383 - kedro.io.data_catalog - INFO - Loading data from `model_input_test` (ParquetLocalDataSet)...
 60%|████████████████████████████████████████████████████████████████████████████████████████████████▍                                                                | 1796/3000 [00:05<00:14, 82.40it/s]2019-11-26 05:15:51,819 - kedro.io.data_catalog - INFO - Loading data from `fitted_scaler` (PickleLocalDataSet)...
 61%|█████████████████████████████████████████████████████████████████████████████████████████████████▌                                                               | 1819/3000 [00:06<00:18, 62.64it/s]2019-11-26 05:15:52,234 - kedro.io.data_catalog - INFO - Loading data from `numeric_summary_stats` (PickleLocalDataSet)...
 61%|██████████████████████████████████████████████████████████████████████████████████████████████████▌                                                              | 1836/3000 [00:06<00:22, 51.74it/s]2019-11-26 05:15:52,649 - kedro.io.data_catalog - INFO - Loading data from `ordinal_summary_stats` (PickleLocalDataSet)...
 62%|███████████████████████████████████████████████████████████████████████████████████████████████████▏                                                             | 1849/3000 [00:07<00:26, 43.28it/s]2019-11-26 05:15:53,506 - kedro.io.data_catalog - INFO - Loading data from `computed_mcmc_model` (PickleLocalDataSet)...
 62%|████████████████████████████████████████████████████████████████████████████████████████████████████▌                                                            | 1873/3000 [00:08<00:33, 33.97it/s]2019-11-26 05:15:54,098 - kedro.io.data_catalog - INFO - Loading data from `model_results_df` (CSVLocalDataSet)...
2019-11-26 05:15:54,104 - root - INFO - Applying complete shift policy for cluster 0, scenario: ['c0_1_sd_shift', [0], True, False, [0, 0, 0, 0], ['aap_cnt_in_20m', 'auto_service_and_maintenance_500', 'change_autozone_cnt_in_5m', 'change_family_dollar_cnt_in_5m']]
2019-11-26 05:15:54,105 - root - INFO - Estimating target variable change_diy_tnx_cnt using model
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3000/3000 [00:16<00:00, 185.90it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3000/3000 [00:10<00:00, 293.14it/s]
2019-11-26 05:16:07,912 - root - INFO - Creating intervention table for features ['aap_cnt_in_20m', 'auto_service_and_maintenance_500', 'change_autozone_cnt_in_5m', 'change_family_dollar_cnt_in_5m'] using sd
2019-11-26 05:16:07,915 - root - INFO - Feature aap_cnt_in_20m: standardized value 0, true value 0.0
2019-11-26 05:16:07,916 - root - INFO - Feature auto_service_and_maintenance_500: standardized value 0, true value 0.0
2019-11-26 05:16:07,917 - root - INFO - Feature change_autozone_cnt_in_5m: standardized value 0, true value 0.0
2019-11-26 05:16:07,918 - root - INFO - Feature change_family_dollar_cnt_in_5m: standardized value 0, true value 0.0
2019-11-26 05:16:07,918 - root - INFO - Estimating target variable change_diy_tnx_cnt using model
you've clicked 0 times