async-dash is an async port of Plotly Dash library, created by replacing its flask
backend with its async counterpart quart.
It started with my need to be able to create realtime dashboards with dash, specifically with event-driven
architecture. Using async-dash with components from dash-extensions
such as WebSocket, EventSource, etc. you can create truly events based or realtime dashboards.
pip install async-dashfrom async_dash import Dash
from dash import html, dccSimple Example
import asyncio
import random
from async_dash import Dash
from dash import html, Output, Input, dcc
from dash_extensions import WebSocket
from quart import websocket, json
app = Dash(__name__)
app.layout = html.Div([WebSocket(id="ws"), dcc.Graph(id="graph")])
app.clientside_callback(
"""
function(msg) {
if (msg) {
const data = JSON.parse(msg.data);
return {data: [{y: data, type: "scatter"}]};
} else {
return {};
}
}""",
Output("graph", "figure"),
[Input("ws", "message")],
)
@app.server.websocket("/ws")
async def ws():
while True:
output = json.dumps([random.randint(200, 1000) for _ in range(6)])
await websocket.send(output)
await asyncio.sleep(1)
if __name__ == "__main__":
app.run_server()In addition to all the advantages of writing async code, async-dash enables you to:
- run truly asynchronous callbacks
- use websockets, server sent events, etc. without needing to monkey patch the Python standard library
- use
quart/fastapi/starletteframeworks with your dash apps side by side - use HTTP/2 (especially server push) if you use it HTTP/2 enabled server such
as
hypercorn.
I'm maintaining this library as a proof of concept for now. It should not be used for production. You can see the
deviation from dash here.
If you do decide to use it, I'd love to hear your feedback.
dash-devices is another async port based on quart. It's capable of using websockets even for callbacks, which makes
it way faster than either of dash or async-dash. However, the library stands outdated at the time this document was
last updated.
PS: async-dash is highly inspired by the dash-devices. Difference being that async-dash tries to follow dash
as close as possible.
- Exception handling in callbacks in debug mode is broken. So its disabled internally.
- Write examples/articles showcasing the use cases for asynchronous
dash. - Gather reviews and feedback from the Dash Community.