✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

[Sharing insights] Using assets_folder for apps where the assets folder is not in the root of the project

I haven’t been this documented, so I thought it was worth to share with others.

If you, like I do, want to have your project structure with something similar to this:

myproject
├── bin
├── MANIFEST.in
├── myproject
│ ├── app.py
│ ├── assets
│ ├── init.py
│ └── main.py
├── README.md
├── setup.py
└── tests

and you run it through python myproject/app.py or python -m myproject;
You will find that the assets/ folder is not served automatically by Dash as it is explained here. So in order to that folder (myproject/assets) to be served properly, you need to specify the assets_folder argument when you create the Dash instance. Something like this:

assets_folder = os.path.join(os.path.dirname(os.path.abspath(file)), ‘assets’);
[…]
app = app = dash.Dash(assets_folder=assets_folder)

However, you don’t need to use the assets_url_path argument which, if I understood correctly, is meant to specify a different name of the folder inside the assets_folder.

The assets_url_path is for having a different name to serve the assets, instead of /assets/ routes it can be something like /files/ (your folder still named assets).

We just updated the docs to include the undocumented features, guess assets_folder didn’t make it thru. But yes, it is an absolute path to the folder where the assets resides.

2 Likes