Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Websockets, devices, performance gains

Hi all,
I wanted to share what we’ve been working on.

Our original intention was to make Dash work better with devices/hardware. Along the way, we discovered that websockets can give Dash a significant improvement in performance. (We modified Dash to use websockets instead of HTTP requests.)

Among other changes, we’ve added shared callbacks:


Let us know your thoughts. Hope all’s good out there. :slight_smile:


This looks well thought out! Will keep it in mind if the need arises.

It looks so cool! I just installed it, and i am now trying it out. In my case, it took following steps,

  • Install python 3.7 (i was on 3.6 before)
  • Install new dependencies via pip (quart, quart_compress, git+https://github.com/richlegrand/dash)
  • Replace the Flask server object by a Quart object (from quart import Quart)

In addition i encountered some issue due to this project being base on Dash 1.11.0 rather than 1.12.0 (e.g. the prevent_initial_callbacks flags is missing). I guess the new version will be merged at some point? :slight_smile:

EDIT: It does however write the following line, which confuses me as i was under the impression that websockets would be used by defaults,

[2020-05-19 18:15:12,932] Running on over http (CTRL + C to quit)

EDIT2: I have merged v1.12.0 into your code, and now everything just seems to work!

Hi Emil,
If you try running from the git repository, you’ll run into some issues unless you build and install the modified dash_renderer.

The quicker/easier approach is to follow the instructions on the page, which is to download the tar file:


  1. Install quart and quart_compress: pip3 install quart, pip3 install quart_compress
  2. Uncompress and untar dash-devices.tar.gz.
  3. Go into dash-devices directory and run one the examples (e.g. python3 example1.py ). It assumes that you have a recent version of Dash already installed. (Note, running the examples in this directory won’t modify your existing Dash installation.)
  4. Point your browser to localhost:5000 .
  5. Repeat (4) with another browser tab.

dash_renderer is precompiled and ready to use if you go this route, so you can just run the examples and play with things without having to compile and install the modified renderer.

Thanks for the pull request. :slight_smile:

Hi @narragansett
The GitHub link above is not working

Hi @narragansett
Can you please share in layman’s terms how this would help Dash work better with devices. I read all the documentation that you put on github, and I understand that it would make things faster.

But what do you mean by devices? Are we talking about phones or tablets? And what kind of challenges were Dash apps having when on devices?

I appreciate it,

Whoops, sorry about that – this link should work:


Regarding devices-- I’m talking about using Dash as a front-end for a device. This is an example of such a device.

Here are the issues we encountered:

In particular, the ordering of HTTP requests used for component updates can result in incorrect behavior if there’s a device on the server side.

I guess that @narragansett means by devices is a piece of hardware to be controlled/monitored, e.g. a sensor or a camera.

1 Like

Wo super nice! I have been looking for this quite some while. Would be nice if It could be integrated in to the main dash repo.

1 Like

thanks :slight_smile:

I think using Python’s asyncio is the best approach for integrating WebSockets into Dash. Unfortunately you need to use Python 3.6 or higher. I suspect that’s a big hurdle for getting (any) of this code integrated.

1 Like

The dash code works on python 3.8, so should work? Another nice thing would be to create an package from it. So you could import the decorators, would this be possible? (And replace the flask server with the one you are using)

As changes are made to core parts of the Dash code, I don’t think it is possible to create a package, though it would have been cool (:

I was guessing that Python version 3.6 or greater is a restriction not easily swallowed by the Dash code maintainers.

Making a package that works side-by-side with regular Dash should be doable.


Ah ok I understand, probably you are right

Hope all’s well out there. We posted a pypi package for dash_devices that runs side-by-side with Dash:

To give it a try:

  1. Make sure you have a recent version of Dash installed.
  2. Install quart and quart_compress: pip3 install quart pip3 install quart_compress
  3. Install dash_devices: pip3 install dash_devices
  4. Download one of the examples (e.g. example1.py) and run it (e.g. python3 example1.py ).
  5. Point your browser to localhost:5000 .
  6. Repeat (5) with another browser tab.

Enjoy :slight_smile:


Is there a particular reason for using quart over other ASGI frameworks? Would FastAPI also work? Does anybody know if the Dash developers consider moving from WSGI to ASGI with native async?

We chose Quart because it’s API was most similar to Flask and had built-in WebSocket support (and it used asyncio). FastAPI looks interesting and it also has built-in WebSockets… porting looks straightforward.

The Dash code maintainers haven’t commented on using asyncio in the future. It would mean dropping Python2 and earlier versions of Python3. asyncio is growing in popularity. There are opportunities for significant performance gains with Dash and asyncio.

1 Like