Import packages for dash sub-app already existing

Viewed 161

I created a Dash application which is running fine on it's own (with no import issues). Other users also created application that we now want to merge into a single application with a general index linking every application. I can't find a solution to load a package I created. I want to run the application on it's own (debugging purpose) and via the general index (production purpose).

Here is the structure for my app (similar to what is detailed here on the Dash documentation):

+ app.py --> creates the dash server
+ layout.py --> Defines my page layout
+ callbacks.py --> I imported packages here (import package as pk) that will fail when run via the general index
+ package --> the packages I created

After I merged the project, my structure looks like that (via a git submodule add):

+ app.py
+ index.py --> will call the layouts
+ initial app folder (git submodule from structure above)
  + __init__.py
  + the files above

When I start the server, I get the error message pk.something error, pk is not defined. I can't find a solution to have the application run standalone and within the general index. I tried to move the import (in app.py or in the new __init__.py) but nothing works. My next attempt will be to move the package in a new subfolder. Does anyone know if that will work ?

1 Answers

I got it to work via the app.py file. I don't know if it's a proper solution and I feel I can scale my application in a decent manner. I moved my scripts into folders with a __init__.py

in app.py, I added:

from package import my_package

in callbacks.py, I changed the import;

from app import my_package as pk

Comments are welcome for improvements. I would like to know how far I am from the best solution.

Related