How can I include assets of a dash app into an exe file created with pyinstaller --onefile?

It’s been several years since this thread was last opened but I was unable to find a single resource that showed how to include javascript/css/etc. (basically anything in the assets folder) in the dash executable and have it actually work.

I was finally able to get it working and it’s a relatively simple workaround.

The first thing I did was follow this comment/thread on allowing dash to see the assets folder:

But instead of following this exactly (since it wasn’t working), I modified the call in dash.Dash() to look like this app = dash.Dash(__name__, assets_folder=find_data_file('_internal/assets/'), include_assets_files=True). The find_data_file function is included at the post above. The reason for the ‘_internal’ inclusion was that I noticed once the app is packaged up as an executable when running pyinstaller app.spec all of the included modules (including the assets folder) were ending up in there instead of at the same level as the executable. Since, presumably, assets needs to be accessible at the same level as the executable, I figured I should just point the app to that location beforehand. This also necessitates your assets folder being placed into a directory called ‘_internal’ before you package everything up. You can test out the app to make sure it still has access to those files when running via Python on command line.

The app.spec file also needs to include the ‘_internal’ in the path to the assets folder. So your ‘datas’ variable should look like this:

datas=[('_internal/assets/javascript_stuff.js','assets'), 
             ...,
             ...],

Once I did that, the javascript was accessible by the executable and worked just as expected.

I wanted to share on the off chance someone else needed a workaround for this still. If anyone has any better solutions, I’m still open to them. Nothing seems to have been negatively affected otherwise.