CASO 1. El Valle de Cañete y la Central Hidroeléctrica “El Platanal”
A. Contexto de la Central hidroeléctrica Salcca Pucará
Dash is a Python library, developed by Plotly Technologies Inc. that, behind the scenes, uses Flask as the back-end server and React as the front-end JavaScript framework. It is also a rather popular project, used by over 4K other projects, with about 9.6K stars, 1K forks, and released under an MIT license126. The Dash App Gallery is another great place to take a first look at the project127.
With Dash you can create web applications with HTML and CSS all within Python, and with the use of callback functions (a Python function decorated by dash.Dash.callback) that specify Output (what Dash/HTML element to change, e.g. a graph or a div), Input (what Dash/HTML element triggers -on change- the functions, e.g. “button X was clicked”), and optionally State (something that is read when a function is triggered by the Inputs, e.g. “what is the value of dropdown X when button Y is clicked?”) you can manage the whole interactivity without writing a line of JavaScript. This comes at a small price, and we will discuss that in the next chapter, as well as other limitations and work-arounds.
Dash is extendable by creating your own (or from the community) components in React.js, and using a project boilerplate128 you can easily make them available in Dash. You can also integrate D3.js with Dash129. The documentation is pretty extensive and covers various usage patterns in depth, allowing you to create complex applications, while there is also a repository with examples of advanced functionalities available on GitHub130.
Dash is broken down in several libraries according to their domains. Some were incorporated from community contributions, others were paid by Plotly clients but were
124 https://github.com/seatgeek/fuzzywuzzy 125 https://dash.plot.ly 126 https://github.com/plotly/dash 127 https://dash-gallery.plotly.host/Portal/ 128 https://github.com/plotly/dash-component-boilerplate 129 https://dash.plot.ly/d3-react-components 130 https://github.com/plotly/dash-recipes
open-sourced. Here we will view a few of them, and some that are community- maintained (i.e. outside of Plotly), all of which we used in EDA Miner.
Dash Core Components131 is responsible for high-level components like graphs, dropdowns, sliders, check-boxes, and more.
Dash HTML Components132 contains (almost) every HTML tag like div, button, p, span, h1-h6, and even script.
Dash DAQ133, which was recently open-sourced, contains high-level components that are more geared towards controls like switches, gauges, joysticks, knobs, thermometers, and more.
Dash DataTable134 is a library for creating tables that are highly interactive, and much like spreadsheets you can edit values, add or remove lines or columns, sort, filter, have paging, and more.
Dash Cytoscape135 was also recently released (merely 1.5 months prior to this project‟s start, or 6 month at the time of writing), and is an extension of the popular Cytoscape.js library for network / graph visualizations.
Dash Bootstrap Components136 is an independent community project that ports the Bootstrap project into Dash, giving access to components like modals, navbars, tabs, jumbotrons, cards, and more.
Dash Core Components for Visualization137 is another external project that provides a few extra components: a component to run JavaScript, a network component, and a data-table.
Flask138
Flask is a Python web micro-framework, which means it doesn‟t make too many assumptions for you, nor does it wrap everything around a rigid and opinionated API139. 131 https://dash.plot.ly/dash-core-components 132 https://dash.plot.ly/dash-html-components 133 https://dash.plot.ly/dash-daq 134 https://dash.plot.ly/datatable 135 https://dash.plot.ly/cytoscape 136 https://dash-bootstrap-components.opensource.faculty.ai/ 137 https://github.com/jimmybow/visdcc 138 https://flask.palletsprojects.com/en/1.1.x/ 139 https://flask.palletsprojects.com/en/1.1.x/foreword/
That said, due to their design decisions their API is very simple and polished140, and the scaling of Flask applications is not an issue141. It works by using Werkzeug and Jinja as the underlying mechanisms for a web server gateway interface (WSGI) and template engine respectively. Since sub-classing the Flask object is supported, a lot of applications are based off that, and most notably, the one we used: Dash (to access the Flask server object from the Dash object you call Dash.server).
Flask is, of course, open source as well. The GitHub page shows that is is an immensely popular project with more than 45.8K stars, 12.8K forks, and 550 contributors with a BSD-3-Clause license. It is used by more than 303.7K projects142, with large companies like Pinterest (Steven Cohen cites that it handles “over 12 billion requests” daily (Cohen, 2015)) and LinkedIn (0:45 – 1:15 LinkedIn talk (Sanders, 2014)) being some of them.
As we said, Flask can be sub-classed to create wrappers, but the primary focus of the development community is designing extensions (Sanders, 2014) and we will see a few of them here:
Flask-Login143 is an extension that helps with user authentication, session management, “remember me”, and anonymous users, among others. What is lacks is handling of permissions (an interesting Flask extension is Flask-Security), registration, and account recovery. As a GitHub project, it has nearly 2.2K stars and 500 forks, with 78 contributors and an MIT license144.
Flask-WTF145 is an extension that helps with Forms, the validation of input, CSRF protection, reCAPTCHA and more. The GitHub project uses a BSD License, is used by about 45.3K other projects with nearly 1K stars and 240 forks, with 69 contributors146. 140 https://flask.palletsprojects.com/en/1.1.x/design/ 141 https://flask.palletsprojects.com/en/1.1.x/becomingbig/ 142 https://github.com/pallets/flask 143 https://flask-login.readthedocs.io/en/latest/ 144 https://github.com/maxcountryman/flask-login 145 https://flask-wtf.readthedocs.io/en/stable/ 146 https://github.com/lepture/flask-wtf
Flask-Mail147 is an extension for that provides a simple API to handle mails via SMTP, using a simple dictionary for passing configurations. It is also popular, with 22 contributors, more than 100 forks, 400 stars, and 12.8K projects using it, with a BSD license148.
Flask-SQLAlchemy149 is the Flask extension developed by the core Flask team that supports the Python library SQLAlchemy. It is, essentially, an Object- Relational Mapping (ORM). Used by more than 79.6K projects, with about 2.7K stars, 700 forks, and 82 contributors, it is also shared on GitHub under a BSD-3- Clause license150.
Flask-Caching151 is the last Flask extension on our list, which provides caching support using any of Werkzeug‟s caching back-ends (we use it with the preconfigured Redis) plus custom ones via sub-classing. The GitHub projects sits on the less used side, with about 2.2K projects using it, 400 stars, 70 forks, 60 contributors, and a mixed BSD license152.
Others
We used other frameworks and libraries too, but the limited usage (and the limited space here) won‟t allow us to go into too much detail, especially since the Dash code- base is bigger by far. We will only focus on JavaScript (JS) which, in itself, needs no introduction. We used a bit of “vanilla” JavaScript but the two frameworks we mostly used were React and jQuery:
React153 is an open-source library / framework for creating component-based interactive elements. Writing JSX (essentially JS with a few extras) to extend the React base Component class, compiling with Babel, and optionally using any library (e.g. installed via the Node Package Manager), you can easily create complex components and single-page apps. React is developed by Facebook, 147 https://pythonhosted.org/Flask-Mail/ 148 https://github.com/mattupstate/flask-mail 149 https://flask-sqlalchemy.palletsprojects.com/en/2.x/ 150 https://github.com/pallets/flask-sqlalchemy 151 https://flask-caching.readthedocs.io/en/latest/ 152 https://github.com/sh4nks/flask-caching 153 https://reactjs.org/
initially released in 2013 (Occhino & Walke, 2013), and the GitHub code is distributed with an MIT license. It is the most popular library of what we saw with 1.3K contributors, 134K stars, 25K forks, and a whooping 2.33M projects using it154.
jQuery155 also a JS library but also comes packages with User Interface elements, and even though it is a bit older, being first published in 2006 (York, 2009), and despite its GitHub page being much less popular (52K stars, 18.4K forks, 347K usages, 275 contributors, MIT license156, it has been steadily increasing in usage across the most popular websites: among the top million websites it was
reportedly used in 63% of them in 2015
(https://www.maxcdn.com/blog/maxscale-jquery/), 69% in 2017
(http://web.archive.org/web/20170219042532/https://libscore.com/) and 73% in 2018 (https://trends.builtwith.com/javascript/jQuery).