Multi Page Apps: circular reference when importing app
See original GitHub issueI define my dash app instance in app.py:
server = flask.Flask(__name__)
app = Dash(__name__,
plugins=[dl.plugins.pages],
external_stylesheets=external_stylesheets,
external_scripts=external_scripts, server=server)
By default the pages plug-in iterates over the modules in the ./pages folder. I have a page that needs to reference the dash app instance in order to call the get_asset_url() method.
In my page module, the import:
from app import app
Creates a circular reference. I can fix this with an embedded import but I’d prefer not to. Is there a way to resolve this? Ideally a proxy reference to the current dash instance (dash.current_app) would be one solution.
Cheers.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Importing model classes from other apps without causing ...
Running into circular importing means you are fighting against the separation you've created, or you're not writing appropriately decoupled ...
Read more >Multi-Page Apps and URL Support - Dash Plotly
If you want to build a multi-page app without Pages, see the Multi Page Apps ... the Dash file (usually app.py ), then...
Read more >Multiple Component Instances - Circular Reference Error
I have been experimenting with Components in order to make some very useful reusable controls. I have created a Component that is basically ......
Read more >How to Eliminate Circular Dependencies from Your JavaScript ...
Circular dependencies (also known as cyclic dependencies) occur when two or more modules reference each other. ... // file a.ts import { b...
Read more >Issues · plotly/dash-labs - GitHub
Multi-Page Apps [Feature Request] Prevent ID collisions. #75 opened on Jan 12 by AnnMarieW · Multi Page Apps: circular reference when importing app....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@stevej2608, @M4thM4gician To solve the circular reference issue we will be adding the following functions that will be similar to
dash.callback
where theapp
object is not needed. This is on the project plan to be completed beforepages/
is moved into Dash.dash.get_relative_path
dash.strip_relative_path
dash.get_asset_url
This is a good first issue. Here are some tips for getting started:
Related issues:
dash.long_callback
as raised on the forum in the post from @ bigmike
Just to add to this, the same issue occurs with the dashboard engine for enterprise users. The workaround is easy enough by simply registering the dashboard engine page and declaring its layout inside the app.py file. However, for code organization, it would be nice to eventually be able to break this code and the associated callbacks into its own file.