Nick Earl
This repository provides a fully functional Flask/Dash app template with built-in support for:
- Multi-page Dash application structure
- Authentication via Google SSO
- Background task processing using Celery & Redis
- Example pages and components to kickstart development
This template is designed to streamline Dash app development for both humans and AI agents with modularity, scalability, and deployability in mind.
- Multi-Page Support: Easily add new pages following the provided structure.
- Google SSO Authentication: Secure login functionality using Google OAuth.
- Celery & Redis Integration: For background job processing and scheduling.
- Prebuilt Example Pages: Includes sample pages with interactive Dash components.
- Deployment Ready: Includes a
Procfilefor deployment on services like Heroku. - Data Connectors:
connectors.pyprovides prebuilt integrations for Amazon S3 and Amazon Athena.
dash-template/
│── dash-template/
│ │── app.py # Main Dash app entry point
│ │── conf.py # Configuration settings
│ │── connectors.py # Handles external API/database connections
│ │── biutils.py # Utility functions
│ │── .env # Environment variables (not included in repo)
│ │── Procfile # Deployment configuration
│ │── dash_app/
| | |── pages/
| | | | home.py # UX entry point
| | | | example.py # Example app page
| | |── assets/ # Stylesheets, images, data files
│ │ │── dash_app.py # Dash configuration
│ │ │── callbacks.py # Dash interactivity logic
│ └── README.md # Project documentation
- Python 3.8+
- Redis (for background tasks)
- Virtual environment (optional but recommended, using
pyenvandpyenv-virtualenv)
If you prefer managing Python versions and virtual environments with pyenv, follow these steps:
- Install
pyenv(Linux/macOS):Follow the instructions to update your shell configuration.curl https://pyenv.run | bash - Install
pyenv-virtualenv:Enable it in your shell profile (e.g.,git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv.bashrcor.zshrc):eval "$(pyenv init --path)" eval "$(pyenv virtualenv-init -)"
- Restart your terminal and install Python:
pyenv install 3.10.6 # Install your desired Python version pyenv virtualenv 3.10.6 dash-template-env pyenv activate dash-template-env
-
Clone the repository:
git clone https://github.com/your-repo/dash-template.git cd dash-template -
Create and activate a virtual environment (using
pyenv-virtualenvif installed):pyenv virtualenv 3.10.6 dash-template-env pyenv activate dash-template-env
Alternatively, use
venv:python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up Environment Variables:
- Copy
.env.exampleto.envand configure required variables. - Generate secure keys for Flask and encryption:
Copy the generated output and paste it into your
python -c "import secrets, base64, os; print(f'FLASK_SECRET_KEY=\"{secrets.token_hex(16)}\"'); print(f'ENCRYPTION_SECRET_KEY=\"{base64.urlsafe_b64encode(os.urandom(32)).decode()}\"')".envfile.
- Copy
-
Run the App Locally (from project folder):
flask --app app run -p 1701
-
Start Redis and Celery:
redis-server & celery -A app:celery_app worker --loglevel=INFO --concurrency=2
- Access the app at
http://127.0.0.1:1701/. - Authentication requires setting up Google OAuth credentials.
- Additional pages can be added in the
dash_app/folder following the provided examples. - The
connectors.pymodule enables integration with Amazon S3 and Amazon Athena, allowing seamless data retrieval and storage.
heroku create my-dash-app
heroku addons:create heroku-redis:hobby-dev
heroku config:set $(cat .env | xargs)
git push heroku main
heroku ps:scale worker=1To deploy on a cloud platform like Heroku or AWS:
- Ensure
Procfileis correctly set up. - Configure required environment variables.
- Use
gunicornto serve Flask (gunicorn -w 4 app:server).
heroku create my-dash-app
heroku addons:create heroku-redis:hobby-dev
heroku config:set $(cat .env | xargs)
git push heroku main
heroku ps:scale worker=1