Plotly Dash Templating and Deployment Tools
Project description
About
dashtools is an open-source toolchain for Plotly Dash. With a user-friendly command line interface, creating Dash applications and deploying them to Heroku has never been quicker.
Includes user and developer-friendly app templates where generating a new app only takes seconds. In fact, it will take longer to install this tool than it will to use it.
Installation
Ready to use dashtools? Installation is easy with pip:
pip install dash-tools
Requires:
- Git CLI which can be downloaded Here
- Heroku CLI which can be downloaded Here
- OS Linux, MacOS, Windows
- Python Version ≥ 3.6
Usage Examples
A. Create an App
-
Create a Dash project in a new directory called "MyDashApp" (using your terminal or command prompt):
Note
"MyDashApp" can be changed to any name. However, for the purpose of this tutorial, we recommend keeping it as "MyDashApp".dashtools init MyDashApp
-
Open the default
app.py
file that comes with this project:Windows
.\MyDashApp\src\app.py
Linux and Mac OS
./MyDashApp/src/app.py
-
Replace the code in
app.py
with your own app code. Make sure to keep theserver = app.server
right after app instantiation:
-
Make sure you are in your project's root directory:
cd MyDashApp
-
Run your app to ensure it works:
Linux and Mac OS
python src/app.py
Windows
python src\app.py
Deploy App to Web with Heroku
-
Deploy to Heroku:
dashtools heroku --deploy
Alert!
After the `requirements.txt` file is created, compare the libraries your app is using with the libraries in the `requirements.txt` file. If your app uses additional libraries, make sure to add them to the requirements file before moving forward with the subsequent steps of deployment.
Pushing App Changes to Heroku (Optional)
-
If you make changes to your app after deploying it, push them to Heroku using:
dashtools heroku --update
B. Create an App with Local CSV sheet
A common use for Dash is to display CSV data that is located inside the project folder. For this, you can use the CSV DashTools template to create a project with CSV data.
-
Using App template with CSV
dashtools init MyCSVApp csv
-
Replace the code in
app.py
with your own app's code, like shown in example A above. Make sure to keep code lines 13, 26, and 27.- 13:
server = app.server
- 23:
PATH = pathlib.Path(__file__).parent
- 24:
DATA_PATH = PATH.joinpath("data").resolve()
- 13:
-
Replace the default CSV file in the
data
folder with your own CSV file -
Make sure you are in your project's root directory:
cd MyCSVApp
-
Run your app to ensure it works:
Linux and Mac OS
python src/app.py
Windows
python src\app.py
Deploy App to Web with Heroku
-
Deploy to Heroku:
dashtools heroku --deploy
Alert!
After the `requirements.txt` file is created, compare the libraries your app is using with the libraries in the `requirements.txt` file. If your app uses additional libraries, make sure to add them to the requirements file before moving forward with the subsequent steps of deployment.
Pushing App Changes to Heroku (Optional)
-
If you make changes to your app after deploying it, push them to Heroku using:
dashtools heroku --update
C. Additional Examples
Tutorial - Making Changes and Deploying to Heroku
Templates
Templates contain boilerplate code for projects, making it much easier to start with useful baseline apps. Example A shown above uses the "default" template, as no template argument was specified. Example B shown above uses the "csv" template.
Available Templates
-
To list out available templates, use the
templates --list
command:dashtools templates --list
Click the dropdowns below to see screenshots.
Template: 'advanced'
To use this template, type:
dashtools init MyFuturisticApp advanced
Advanced multi-page template. Includes examples of ClientsideCallbacks, multi-page routing, external stylesheets, header, footer, and 404 page.
Template: 'csv'
To use this template, type:
dashtools init MyCSVLoaderApp csv
Example of CSV file loading. Includes the default CSV load example from Plotly.
Template: 'default'
To use this template, type:
dashtools init MyAmazingApp default
Basic Dash template. See Dash Docs
Template: 'fastdash'
To use this template, type:
dashtools init StellarDashApp fastdash
Fast Dash template. See Fast Dash Docs
Template: 'iris'
To use this template, type:
dashtools init MyFantasticApp iris
Iris theme. See Faculty.ai Example
Template: 'leaflet'
To use this template, type:
dashtools init BestMapApp leaflet
Dash leaflet plugin. See Dash Leaflet
Template: 'mantine'
To use this template, type:
dashtools init MyGreatApp mantine
Basic mantine template. See Dash Mantine
Template: 'multipage'
To use this template, type:
dashtools init MyPristineApp multipage
New multipage theme. See Multipage Plugin
Template: 'sidebar'
To use this template, type:
dashtools init MySnazzyApp sidebar
Sidebar theme. See Faculty.ai Example
Template: 'tabs'
To use this template, type:
dashtools init MyBeautifulApp tabs
Tabs theme with dynamically generated content. See Faculty.ai Example
-
To use a certain template, simply choose a directory name, followed by one of the template names listed above. Here, we will choose "tabs":
dashtools init MyWonderfulApp tabs
-
Follow the steps in Example A to replace default app with your own app and deploy to heroku.
Format
Templates may include different components, modules and layouts. They have the following format:
AppName
│-- Procfile
│-- README.md
│-- requirements.txt [1]
│-- runtime.txt
│
└── src
|-- app.py
|-- __init__.py
|-- assets/ [2]
|-- containers/ [2]
|-- components/ [2]
└-- data/ [2]
[1] Created during deployment
[2] Not included in all templates
Commands
Usage
dashtools <command> [options]
Commands and Options
heroku
Handle Heroku deployment. Choose option:--deploy
Deploys the current project to Heroku--update [remote name (OPTIONAL)]
Push changes to existing Heroku remote
init <app name> [template (OPTIONAL)]
Create a new app--dir, -d
Specify alternative create location
run
Run app locally from the current directory--set-python-shell-cmd
Specify the python shell command, e.g. python3 or python3.exe, etc.
templates
List and create templates--init <directory to convert>
Creates a template from specified directory--list
List available templates
Other Options
--help, -h
Display help message--version, -v
Display version
Troubleshooting
Running into issues? Outlined below are common errors and solutions. If you do not find an answer below, please Submit an Issue Ticket.
Common heroku --deploy Issues
Error when creating requirements.txt file
Problem: You encounter an error when generating a requirements.txt file
Solution: Verify that you are running the dashtools heroku --deploy
command from a valid plotly dash app directory. E.g. there is a src/app.py
file.
No webpage displayed after Heroku deployment, no error messages
Problem: You are able to deploy your project online to Heroku, but nothing is displayed on the page
Solution1: This may be due to missing libraries that your app needs to run successfully. Check the requirements.txt. file.
Solution2: This may due to the fact that you forgot to add server = app.server
to you main app.py file
Procfile is incorrect
Problem: When deploying, you get an error "Procfile is incorrect"
Solution: When deploying an app, the Procfile is checked for validity. Make sure that your Procfile points to the correct server entrypoint, e.g. server = app.server
.
No solution found
Solution: Try typing into the terminal or command prompt heroku logs --tail
. This will give you access to the official heroku logs of your app that enable monitoring your stack error troubleshooting
Common heroku --update Issues
Your account has reached its concurrent build limit.
Problem: When you try to update and redeploy your app to Heroku too many times within 10 minutes, you will get the above error message
Solution: First, wait a few minutes and try again. If that doesn't work, check out a few possible solutions in this thread.
Unable to update heroku app
Problem: When you try to update your app, you get an error "Unable to update heroku app. Is the project already deployed?"
Solution: Make sure you have already run git init
in the project root directory, and that you have already followed steps to deploy your project to heroku with dashtools heroku --deploy
If both of these steps do not work, verify that the heroku
remote was added by running git remote
. If you do not see it, try re-deploying your app or manually push to the correct remote with the dashtools heroku --update <remote>
option, where <remote>
is replaced with the correct remote.
Common init Issues
No write permission
Problem: You receive a 'write permission' error while trying to init a new app
Solution: Please check your write permissions for the current directory. Try the init command from a different directory.
Common run Issues
No valid python command found for your system
Problem: You encounter an error: No valid python command found for your system when trying to run your app
Solution: Set the python shell command with "dashtools run --set-python-shell-cmd ". The correct command will be the python command that runs python, eg. python, python.exe, python3, python3.exe on your system. Note that although you may be able to run 'python' from your terminal, this may be an alias command for your terminal, and not the correct command.
No such file or directory
Problem: You encounter an error: 'No such file or directory' when trying to dashtools run
your app
Solution: Verify that you are running the dashtools run
command from within a valid project root directory. Your app must be named app.py
, or have a valid Procfile pointing to the app file.
Invalid Procfile
Problem: When you try to run, you get an error "Invalid Procfile"
Solution: When you run an app, the Procfile is checked for validity. Make sure that your Procfile points to the correct server entrypoint, e.g. server = app.server
.
Development
See the Developer Guide for more details.
License
MIT License. See LICENSE.txt file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.