A working example of packaging a Plotly Dash app with background callbacks using PyInstaller. Tested on macOS, should work cross-platform. Based on toy example at plotly/dash#1885 (comment).
git clone
the github repo and cd
into the project directory. Then
create and activate a virtual environment
python3 -m venv .venv
source .venv/bin/activate
install the dependencies
pip install -r requirements.txt
Make a .spec
specification file for the build.
See the PyInstaller docs for options.
pyinstaller main.py
in the new main.spec
file, add the following to the datas
in Analysis
a = Analysis(
...,
datas=[
('long_callbacks', 'long_callbacks'),
('cache', 'cache')
],
...
)
build the app bundle
pyinstaller --noconfirm main.spec
run the app by running the executable or app bundle in the dist
directory
(depends on OS and build specs)
# e.g., on macOS
./dist/main/main