Skip to main content

Async port of the official Plotly Dash library

Project description

Async Dash

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.

Table Of Contents

Installation

pip install async-dash

Usage

from async_dash import Dash
from dash import html, dcc

Simple 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()

Motivation

In addition to all the advantages of writing async code, async-dash enables you to:

  1. run truly asynchronous callbacks
  2. use websockets, server sent events, etc. without needing to monkey patch the Python standard library
  3. use quart / fastapi / starlette frameworks with your dash apps side by side
  4. use HTTP/2 (especially server push) if you use it HTTP/2 enabled server such as hypercorn.

Caveats

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.

Alternatives

dash-devices

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.

Known Issues

  1. Exception handling in callbacks in debug mode is broken. So its disabled internally.

TODO

  1. Write examples/articles showcasing the use cases for asynchronous dash.
  2. Gather reviews and feedback from the Dash Community.

Download files

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

Source Distribution

async-dash-0.1.0a1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

async_dash-0.1.0a1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file async-dash-0.1.0a1.tar.gz.

File metadata

  • Download URL: async-dash-0.1.0a1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.12 Darwin/21.2.0

File hashes

Hashes for async-dash-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 5b861a3adeeb32f4e3cd3e67a866f5f97c264a2b2be3efe2e3cacc13efd05234
MD5 0e85afcb93c3efc1b8178c20aeae7d44
BLAKE2b-256 e511c48a39016f3022b5f2c14369153f243350dc3020ee45f4ee52bd10a8b1fe

See more details on using hashes here.

File details

Details for the file async_dash-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: async_dash-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.12 Darwin/21.2.0

File hashes

Hashes for async_dash-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 47d3c50acc97d30f131c9177062e538d121c2e4f0ff09ab85f6ae2e291bed6ba
MD5 1952efcd89d99dc9db28024775934eeb
BLAKE2b-256 ce1186e672fc9994b6c534e311789f316ce9209cd9b912254a632c9918d7605e

See more details on using hashes here.

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