Fast Dash — Changing how Python web apps are built and deployed

Fast Dash makes prototyping and deploying machine learning web applications lightning fast!

Kedar Dabhadkar
5 min readAug 23, 2023
Fast Dash’s “@fastdash” decorator makes building and deploying Python web applications a breeze! Image by author.

If you are a machine learning practitioner or hobbyist, I bet you enjoy exploring the latest and greatest tools and sharing them with colleagues, friends, and your network.

Enter Fast Dash: a revolutionary Python library crafted with you in mind. It seamlessly transforms your Python functions into deployable web applications, allowing you to focus on the nuances of machine learning and worry about the nitty-gritty of web development.

Let’s be honest: a lot of app development time is spent figuring out user interfaces and how different components talk to each other. After countless hours building web apps, it struck me: why not automate a big chunk of this? That inspiration led to Fast Dash, designed to get your web apps up and running in record time.

Here’s a simple example: creating a web app that displays Matplotlib charts to give you a taste of what Fast Dash can do.

Fast Dash allows the use of a simple decorator to automatically transform Python functions into web applications. Image by author.

Fast Dash is pretty intuitive. It reads everything about your Python function, examining elements like its name, input and output argument labels, data types, and docstrings. With all this information, it designs an interactive user interface on the fly and then deploys it as a full-blown web application!

Read on for details about how Fast Dash works, how to get started, and how to customize your apps. If you’d instead give it a whirl first, just pip install fast-dash . Check out the GitHub repo and the documentation to learn more.

How does Fast Dash work?

Fast Dash is based on two foundational principles.

  1. Every web application can be distilled down to a single Python function.
  2. With thorough annotations, a Python function can carry all the blueprint details needed for an interactive web application.

Your Python function and Fast Dash app configurations together determine how the app is deployed and the level of user interaction. Nail down a well-documented function, and you’ll find there’s barely any need to tinker with app settings.

The ability to read and understand Python functions enables Fast Dash to choose the best components and interactivity for your app. As of now, Fast Dash supports a Plotly Dash backend only. This means that Fast Dash can be deployed like any other Flask app.

Building your Fast Dash apps

Just slapping @fastdash before your Python function is the easiest way to build a Fast Dash app. With the@fastdash decorator, Fast Dash deploys your function eagerly. Let’s break it down with a basic example:

from fast_dash import fastdash

@fastdash
def text_to_text_function(input_text):
return input_text
# * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)

The outcome? Check it out:

Interactive result of a simple text-to-text Fast Dash app. Image by author.

But Fast Dash’s charm doesn’t stop at simple tasks. Armed with the right input and output type hints, it’s capable of deploying even the most intricate Python functions.

Consider this example:

import PIL
import matplotlib.pyplot as plt
from fast_dash import fastdash, Graph

output_layout = """
AB
AC
"""
@fastdash(mosaic=output_layout, theme="BOOTSTRAP")
def multiple_output_components(start_date: datetime.date, # Adds a date component
upload_image: PIL.ImageFile, # Adds an upload component
fips: str = ["01007", "01008", "01009"]) # Adds a single-select dropdown
-> (Graph, plt.Figure, plt.Figure):
# Output components are a Plotly graph, and two figure components
"Fast Dash allows using mosaic arrays to arrange output components"
choropleth_map = ... # Plotly Graph code
histogram = ... # Matplotlib figure code
radar_chart = ... # Matplotlib figure code
return chloropleth_map, histogram, radar_chart
# * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)

And voila! Here’s our function in action:

The output of the code written in the previous block. Image by author.

One of the standout features of Fast Dash is its flexibility. While it offers a swift default mechanism to convert data type hints into components, it doesn’t restrict you. You can also employ Dash components directly as type hints, tailoring the components to fit your exact needs.

For example, instead of upload_image: PIL.ImageFile, you can also write upload_image: dcc.Upload(...) . This way, you can customize the component to your liking, bypassing Fast Dash’s default selection for the PIL.ImageFile data type.

Fast Dash can be used to build web apps wherever you use Python. Its versatility is evident across multiple domains. Here are some examples where Fast Dash powered projects in generative AI, language translation, computer vision, and geospatial analytics (NASA models and Geemap) web applications.

Example of a geospatial application built with Fast Dash. The visual, created using Geemap, shows timelapse satellite imagery comparing National Land Coverage (NLCD) between 2001 and 2009. We can see the increase in the land area of Las Vegas and the corresponding decrease in the water levels of Lake Mead. Image by author.

Customizing your Fast Dash apps

Besides allowing rapid deployment, you can tweak and twist various aspects of your web apps to suit your purpose. You can switch the theme, adjust the title and subheader, add social media links, or deploy within Jupyter Notebook instead of a separate port. Read more about customizing here.

For now, let’s focus on customizing the visual arrangement of output components. The concept is all about “mosaics.” Drawing inspiration from Matplotlib’s subplot_mosaic method, Fast Dash lets you craft layouts using an ASCII-esque diagram or a string list.

Each unique letter or string in this mosaic signifies a unique component. This approach is a game-changer, especially when you’re aiming for non-uniform grid layouts.

For example, imagine the output arrangement you want is something like in the following image:

Arrangement of layouts on the screen when the mosaic argument is “ABB \n CDE”. Image by author.

In which case, you can define your mosaic to be “ABB \n CDE”. Fast Dash would then prep for five outputs. Fast Dash divides the space into six equally-sized boxes placed in a 2 x 3 grid. The first output gets the top-left box. The second output stretches across the next two boxes in the top row. And each of the remaining three outputs gets its own box in the row below.

In Conclusion

At its core, Fast Dash is all about simplification. It abstracts away much of the frontend and server management work, allowing developers to focus on what they do best: writing effective, efficient Python code.

It’s not just a tool for rapid prototyping. With its customization options and inherent documentation capabilities, Fast Dash can be a staple in any developer’s toolkit, from the seasoned web dev professional to the budding data scientist.

With Fast Dash, the future of Python-based web app development looks not only brighter but also faster. And in today’s tech landscape, that’s a combination hard to beat.

So, star the repo and pip install fast-dash today!

WRITER at MLearning.ai / Premier AI Video / AI art Copyright

--

--

Kedar Dabhadkar

Data Scientist | Loves discussing applied deep learning, technology, engineering, water, hydrology, and business. linkedin.com/in/dkedar7/