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.
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?
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 127.0.0.1:8051 over http (CTRL + C to quit)
EDIT2: I have merged v1.12.0 into your code, and now everything just seems to work!
Install quart and quart_compress: pip3 install quart, pip3 install quart_compress
Uncompress and untar dash-devices.tar.gz.
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.)
Point your browser to localhost:5000 .
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.
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 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.
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)
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.