question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cyclical callback results in "Error loading dependencies" message, no error message in console.

See original GitHub issue

If a callback has the same output and input, the “Error loading dependencies” message is shown in the browser, but no error is raised in the console.

Here is a MWE, a div that just counts the number of times the callback has occurred:

import re
from time import sleep

import dash
import dash_html_components as html


app = dash.Dash()
app.layout = html.Div("Callback run 0 times", id='counter-div')


@app.callback(dash.dependencies.Output(component_id='counter-div',
                                       component_property='children'),
              [dash.dependencies.Input(component_id='counter-div',
                                       component_property='children')])
def increment_counter(counter_message):
    regex = re.compile("Callback run (\d+) times")
    result = regex.search(counter_message)
    current_count = int(result.group(1))
    new_count = current_count + 1
    sleep(1)
    return "Callback run {:d} times".format(new_count)


if __name__ == "__main__":
    app.run_server(debug=True, port=65002)

I produced this on Python 3.4.3, both in Firefox and Chromium, with this environment:

certifi==2018.1.18
chardet==3.0.4
click==6.7
dash==0.21.0
dash-core-components==0.21.0
dash-html-components==0.9.0
dash-renderer==0.11.3
decorator==4.2.1
Flask==0.12.2
Flask-Compress==1.4.0
idna==2.6
ipython-genutils==0.2.0
itsdangerous==0.24
Jinja2==2.10
jsonschema==2.6.0
jupyter-core==4.4.0
MarkupSafe==1.0
nbformat==4.4.0
plotly==2.5.0
pytz==2018.3
requests==2.18.4
six==1.11.0
traitlets==4.3.2
urllib3==1.22
Werkzeug==0.14.1

The same issue arises if a network of callbacks is cyclical, eg a callback with element A as an input that outputs to element B, which is the input to a callback that outputs to element A.

Allowing cyclical callbacks would be nice, but there should at least be an error raised indicating the problem. I also can’t find anything in the documentation indicating that cyclical callbacks are not possible, but I might not be searching for the right terms.

#125 Seems to have become a catchall for every instance of the “Error loading dependencies” message, regardless of the underlying cause. I thought it would be better to create a separate issue, as I’m fairly certain what the cause is.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vtslabcommented, Apr 25, 2019

I published a workaround at:

http://yaaics.blogspot.com/2019/03/circular-references-in-plotlydash.html

As stated in the blog, allowing intended circular references that can be broken with raise PreventUpdate is still the prefered final solution.

0reactions
alexcjohnsoncommented, May 22, 2019

This particular cycle we now do catch on the Python side, with dash.exceptions.SameInputOutputException

However, a nontrivial cycle is still a problem that gives the dreaded “Error loading dependencies” with no indication anywhere what caused it. Here’s a simple example, that works fine if you comment out either one of the callbacks but fails with both active:

import dash
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash()
app.layout = html.Div([html.Div('a', id='a'), html.Div('b', id='b')])

@app.callback(Output('a', 'children'), [Input('b', 'children')])
def a(b):
    return b

@app.callback(Output('b', 'children'), [Input('a', 'children')])
def b(a):
    return (a or '') + 'A'

if __name__ == "__main__":
    app.run_server(debug=True)

We need to have the devtools capture and display these errors. I don’t see us catching cyclic callbacks on the Python side - even if it worked for the static case it can’t work for dynamically-generated callbacks where the back-end doesn’t know the whole layout. So the front end will need to have this check, therefore it’s redundant to include it in the back end even if in certain cases that would improve the dev experience.

Separately, I’m transferring the issue of allowing cycles and trusting the dev to break them appropriately here from the dash-renderer repo, in prep for merging the two repos -> https://github.com/plotly/dash/issues/730. This issue is just about reporting it when an error is the desired outcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Error loading dependencies" when trying to assess table data
Hello,. I am trying to do the following steps in a Dash program: 1. upload a csv file into a DataTable 2. select...
Read more >
How to fix this ES6 module circular dependency?
The answer is to use "init functions". For reference, look at the two messages starting here: ...
Read more >
e10113.pdf - Oracle Help Center
This manual provides information about the error messages you may encounter when installing and using Oracle Fusion Middleware components. It augments the ...
Read more >
How to fix nasty circular dependency issues once and for all in ...
In the many projects I have maintained so far, sooner or later I always run into the same issue: circular module dependencies.
Read more >
API with NestJS #61. Dealing with circular dependencies
Detecting circular dependencies using ESLint. The provided code example makes it very obvious that there is a circular dependency between files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found