Appsilon Tech Talks – each Wednesday we hold internal meetings where we discuss technology. By sharing our tech talks with the community and contributing to open source, we inspire discussion and growth that allow others to learn from our accomplishments and to share with us.
Lately, I had a chance to present a tech talk about Dash Python framework. Dash is a reactive framework for building Dashboards. They are like ones build using Shiny R framework. At Appsilon we’ve already build complex dashboards in Shiny. We also deployed them for thousands of users.
Python community is catching up and we are happy to explore opportunities. It is worth to compare the two. We’ve started with several internal tests. We already delivered Dash projects for most innovative clients. Starting today we deliver business projects written in Dash for a broader audience. Below you can see a quick summary of our lessons learned!
This tech talk covers basics and more advanced topics. You will start simple to finish with building custom components and scaling.
The broader list of topics covered in the tech talk:
1. What is Dash?
- Dash is a productive Python framework for building web applications.
- Created and maintained by Plotly. https://plot.ly/products/dash/.
- Written on top of Flask, Plotly.js, and React.js.
- Dashboard is implemented in pure Python.
- Dash is an open source library, released under the permissive MIT license.
2. What you get with Dash
- Frontend generated in Python
- Reactive computations abstraction
- Component class for every HTML tag as well as keyword arguments for all of the HTML arguments implemented in dash_html_components package
- Interactive HTML elements implemented in dash-core-components
- Plotly python API implemented in dash-core-components available through Graph class
3. Dash demo application with source code explained.
A deeper look into Dash interactivity and description of how recalculations work.
4. What are the Dash core components? How to build customized components?
You can implement your own components in Dash. For more information on how to do that visit https://dash.plot.ly/plugins
We have started implementing our own components and helpers:
- Leaflet map
- Timeline (react horizontal timeline port)
- Mixpanel hook (to allow using Mixpanel with frontend plugin that identifies user by cookie)
- IncludeScript (includes and runs an external script on demand – useful if app runs in local mode)
5. Single threaded Dash
Graph recalculation is blocking and is single threaded. However, we can extract the flask server that is generated and use gunicorn to make the computations concurrent.
Gunicorn ‘Green Unicorn’ is a Python WSGI HTTP Server for UNIX. It’s a pre-fork worker model. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resources, and fairly speedy.
Seems to still have a limit on concurrent users.
6. Dash limitations
- We still explore how it scales for many concurrent users
- At some point, you will need more sophisticated components than Dash provides by default
- You’ll have to write your own components in React.js
- Or you’ll have to port already existing components from React.js to Dash
- You’ll quickly find out that some quick wins are still under development (Mapbox raster example)
- There are no intermediate values in the reactive graph.
- You have to add hidden div with intermediate data (as suggested by plotly)
- You have to write separate function for every Output which forces you to restructure the code
- There are some issues we may not be able to resolve without getting to know the way Dash works by heart
- There may be still some issues with Dash that we don’t know about – we have to add a margin to our work
7. Questions and Answers session
- Does state stay on the server or on the Client? Compared Shiny and Dash.
- Using memoization as a workaround. Discussing threading with memoization.
- How is specifying reactivity different between Dash and Shiny? Pros and cons of each model.
I hope you like it! Please let me know in the comments what would you like to explore next!
Read the original post at
Appsilon Data Science Blog.