Introducing Asynchronous Dash

Snehil Vijay
2 min readFeb 4, 2022

This article introduces async-dash, an asynchronous port of Plotly Dash, which uses Quart instead of Flask for the backend. You can read more about this project and why it exists here: snehilvj/async-dash.

In this article we will build a simple dash app that plots and updates a line chart using a web socket.

Set up env

Create a virtual environment and install the required libraries.

async-dash requires Python 3.7 or above.

python -m venv .venv
source .venv/bin/activate
pip install async-dash dash-extensions

Create app

Instead of importing Dash from dash, import it from async_dash. Rest remains the same.

from async_dash import Dash
from dash import html, Output, Input, dcc

Create a file called app.py with following contents.

Here we have used the WebSocket component from dash-extensions library. This component will establish a web socket connection between our client (browser) and the server which will then start publishing random data to our client every sec.

The client side callback that we have added will update our line chart as soon as the WebSocket component receives any data from the server.

Lets run this file.

python app.py

This will start a server on http://127.0.0.1:8050. When you open this link in the browser, you will see something like below:

A simple line chart updating every sec with the data it receives via a web socket connection.

Conclusion

This is just a small introduction to async-dash. With async-dash, you can also write truly asynchronous callbacks, use server sent events, etc. If you want to know more about this project or have any feedback, please visit https://github.com/snehilvj/async-dash.

--

--