Skip to main content

Plotly Dash Template Generator and Tools

Project description

🛠️ dash-tools - Easily Create and Deploy your Plotly Dash Apps from CLI (V0.10)

Create a templated multi-page Plotly Dash app with CLI in less than 7 seconds.

Deploy your app to Heroku in under a minute!

About

dash-tools is an open-source toolchain for Plotly Dash Framework. With a user-friendly command line interface, creating Dash applications 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!

Want to deploy your app to the web? We've got you covered. With Heroku support, deploying your project will take under a minute.

Installation

Ready to use dash-tools? Installation is easy with pip:

pip install dash-tools

Find dash-tools on PyPi

Usage Examples

Below are common usage examples. For a more in-depth tutorial on writing apps for Plotly Dash, see the Plotly Dash Documentation. For information about dash-tools commands, read the Commands section.

Creating A New Project

Creating a new Dash project is very simple. The following command will create a new directory called "MyDashApp" from where the command is invoked:

# This command will create the app "MyDashApp" in your current directory.
# MyDashApp will contain all necessary files to make your project
# run, as well as files for deploying to Heroku - see Deploying
# with Heroku in the README below.
dash-tools --init MyDashApp

# You can make changes to your app in the src/app.py file!
# See https://dash.plotly.com/layout
# When you are ready to test it locally you can also run the
# app.py file from terminal:
python MyDashApp/src/app.py

# You can now view the app at http://127.0.0.1:8050/ in your browser.

Using Templates

Templates offer different project styles and include different boilerplate code samples. Creating a new app with a template is easy. Just use the optional template argument after --init. If you do not specify a template, 'default' will be used. See the Templates section below for more details.

# Create a new Dash app called "MyWonderfulApp" using 'minimal' template
dash-tools --init MyWonderfulApp minimal

To list out available templates, use the --templates command:

# Display available templates
dash-tools --templates

# Note: To see details on each template, check out the 'Templates'
# section in README below.
>>> dash-tools: templates: List of available templates:
>>>         > default
>>>         > tabs
>>>         > sidebar
>>>         > iris
>>>         > multipage

Deploying with Heroku

To create a project and deploy to Heroku, it is quite simple. Using the --deploy-heroku command in the project root directory will look for the above files. The directory needs to be a git repository, and the Heroku CLI must be installed.

The command --deploy-heroku takes one argument for the project name, which may only contain lowercase, alphanumeric characters and dashes. It must be unique and not already on Heroku. The process will create a new git remote called 'heroku' with the heroku remote url to push/deploy all project code, and will return a URL of your deployed project with the project name you chose, such as https://your-unique-app-name.herokuapp.com/.

# Create a new app "MyGreatHerokuApp". Any template can be used for this step.
# Procfile and runtime.txt are included with the templates,
# and requirements.txt file will be generated automatically in the next step.
# These files are necessary to deploy to heroku.
dash-tools --init MyGreatHerokuApp

# Change current directory to your new project root directory
cd MyGreatHerokuApp/

# Feel free to make changes to your project at this step!
# See https://dash.plotly.com/layout

# Using the following command will start the deploy process
# Follow the instructions in the console to deploy your app
dash-tools --deploy-heroku your-unique-app-name

And that's really it! A new heroku app and git remote will be created, and all project code will be deployed. To push any changes you make after the application is deployed to heroku, create a git commit and push it to the remote heroku branch:

# Add changes to git staging from the project's root dirctory
git add .

# Create a new commit with a message
git commit -m "Adding some new files"

# Push to the "heroku" remote's "master" branch which was added
# automatically in the example above.
# Your changes will now be sent to heroku, and your app will
# build and be re-deployed automatically.
git push heroku master

Templates

Listed below are available project templates. Please see the above Using Templates section on how to use templates. If you would like to develop templates, please read the Creating Templates section below.

  • default - the default multi-page template. Includes examples of ClientsideCallbacks, multi-page routing, external stylesheets, header, footer, and 404 page.
  • iris - Iris theme. See Faculty.ai Example
  • multipage - New multipage theme. See Multipage Plugin
  • sidebar - Sidebar theme. See Faculty.ai Example
  • tabs - Tabs theme with dynamically generated content. See Faculty.ai Example

Commands

Project Commands

  • --deploy-heroku Args: REQUIRED (unique heroku project name) : Deploys the project to Heroku using the Heroku CLI (Must Install Seperately) and Git. Invoke from the project root directory.
  • --init, -i Args: REQUIRED (project name) OPTIONAL (template) : Creates a Plotly Dash app with the given name in the current working directory. Optional args specified can be used for templates.
  • --templates, -t : List available templates.

Other

  • --help, -h: Display CLI helpful hints
  • --version: Display current version.

Development

Creating Templates

  1. Templates are found here: dash_tools/templating/templates/<Template Name>. When a user uses CLI to choose a template with the name <Template Name> the template will be copied to their system.

  2. Adding a new template to the templates directory requires adding the new template to the Enum list in templating.Templates Enum. Template name must match Enum value, eg.

    class Templates(Enum):
       DEFAULT = 'default'
       MINIMAL = 'minimal'
       NEWTEMPLATE = 'newtemplate'
    
  3. Any file names or files containing the strings {appName} or {createTime} will be formatted with the given app name and creation time. Eg. README.md.template: # Created on {createTime} will copy to the user's filesystem as README.md: # Created on 2022-03-30 22:06:07

  4. All template files must end in .template

License

MIT License. See LICENSE.txt file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dash-tools-0.10.tar.gz (4.1 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page