Exploring Streamlit or Dash to build specific Interactive Web Applications

As a PO, I am not wondering anymore if the Python/AI/ML revolution is a new fad or a real trend? That’s both of it! Like anyone who start something new like I do now with Python and IA, I am currently in the “enthusiastic phase” that tend to transmogrify me as an overzealous supporter like cucumbers are ultimately transmogrified into pickles!

You can find the code on my github account:

You can also watch the videos:

Anyway, this learning process is not without consequences, it definitely calls into question my PO’s practices, habits and skills. Am I a conservative with a fixed mindset ? Or do I accept changes as necessary and essential even though it may say leaving my comfort zone to a more exploratory area! It is almost a cliché dilemma!

I know that all technologies are doomed to disappear or to be replaced. Regarding Python’s potential, the question has
become more and more acute “Will I be, from 1 or 2 years from now, an has-been P.O, knowing only deprecated technology if I do not tackle right now the Python/AI/ML revolution?”. I guess I will answer YES.

By experience, I know also that it is not a direct threat but a progressive one. I heard that meanwhile Python is
steadily progressing, PHP for instance remains popular mostly
due to the 2 killer apps named WordPress and Drupal, legacy! Even though, there are some smoke screen effects due to local exceptions e.g. French development labour market dominated
by Symfony for instance or the worldwide Laravel spectacular breakthrough.

I do not know if It can be considered as a forerunner sign for the actual or future Python hegemony but just google for instance the result number on
Manichean comparisons such as “PHP vs Python”, you’ll be surprised!

Lastly, here is 2 videos, that are addressing this concern on this future trend. The first video is in brazilian, a quite personal testimony but it remains interesting both for practising brazilian and hearing few arguments. The second video gives a very macro vision and quite technical but with a huge historical depth and that’s quite interesting even though a bit technical.

After, the few thoughts, let’s get down to earth!

Professionally, I am a bit utilitarian. Learning something new like Python and IA has to “payback” somehow. I always try to figure out what can I gain from this experience and how can I apply this knowledge on a daily basis before starting up. Sometimes it even turns ridiculous! I must also confess that I didn’t go that far as the guy behind keypressingmonkey*.

See Everything I Automated In 2020 To Save Me Hours Of Time by https://keypressingmonkey.medium.com/. There is also this very truthful testimony about learning coding in I Learned Coding Mostly From Porn

In the meantime, I always deal with these 2 safeguards: obsolescence and time-to-market.These 2 concepts can be sumarized with 1 question: “Is there a purpose to learn something that will be soon deprecated?”. Despite all this questioning, I preserve to learn Python/AI/ML. As a conclusion, what I am looking for in term of feature may require to drop PHP as the only main programming language and turn my known developing paradigm upside down.

So, that is the reason why I have explored especially the ability with Python to build-up quickly applications, leveraging on these 2 python libraries :

This post is my feedback on this experience. Enough conceptual bullshit! Let’s get straight to the point with examples.

My idea is to build a Dashboard in Python, quickly and on-demand, with an existing framework such as Plotly Dash or Streamlit to address a specific need. So, it suppose that you are able to quickly perform the following tasks:

  • Leveraging intensively on a low-code with library like Streamlit or Plotly Dash
  • Quickly and gently retrieving and consolidating heterogeneous data from different sources : mysql dump, csv, pickle, static json file, WP API…
  • Focusing on a very SPA (Single Page Application) approach, respecting the single idea rule: one need, one feature, one screen, one application.

In this exploratory phase, shoddy work is even acceptable so you can focus on feature and value and not on development! But by choosing such a library, it is also picking a great foundation on which you can build any of your application with a relative good manufacturing quality.

Let’s browse some examples.

1. Streamlit

It is truly the ultimate Plug and Play tool for forging an application in data science. Once the installation is done! Creating an app is almost immediate and you obtain a rather conclusive result especially liked with few other libraries (Pandas, Spacy).

You can check the files from my github account.

In comment, in each file, how to launch the python script and the source.

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
[path]
cd /Users/brunoflaven/Documents/01_work/blog_articles/build_interactive_webapps_python_scripts_using_streamlit/02_interactive_webapps_streamlit/
 
[file]
streamlit run 001_interactive_webapps_streamlit_pandas.py
 
 
# more on infos and apps on
https://streamlit.io/
https://streamlit.io/gallery
https://docs.streamlit.io/en/stable/
 
 
"""
 
# Source :: ! ARTICLE_1 How to write Web apps using simple Python for Data Scientists? Check https://mlwhiz.com/blog/2019/12/07/streamlit/

1.1 Streamlit and Pandas

It requires csv files that are in /datas/. We have gather few csv that gather on one file countries, capital and continent from different sources.

001_interactive_webapps_streamlit_pandas.py
002_interactive_webapps_streamlit_pandas.py
003_interactive_webapps_streamlit_pandas.py
003a_interactive_webapps_streamlit_pandas.py
003b_interactive_webapps_streamlit_pandas.py
003c_interactive_webapps_streamlit_pandas.py
004d_interactive_webapps_streamlit_pandas.py
006_interactive_webapps_streamlit_pandas.py
007_interactive_webapps_streamlit_pandas.py
data

Source for the countries and some other infos about countries:

1.2 Streamlit and Spacy

002_streamlit_for_nlp_projects_streamlit_spacy.py
003_streamlit_for_nlp_projects_text_summarization.py
bf_sample_text_1.txt
capture_1_003_streamlit_for_nlp_projects_text_summarization.png
capture_2_003_streamlit_for_nlp_projects_text_summarization.png
capture_streamlit_for_nlp_projects_streamlit_spacy.png
cowboy_silhouette_2.png

2. Dash

To me, Dash is closer to Flask. So, it is closer to a small, lightweight Python web framework to create a website. Still, I have gathered few examples that enable a comparison with Streamlit. There are very convincing examples if you need to prototype quickly a web application.

Definitely, Dash enables you to make great things but the learning curb is much steep and it sounds more like learning a way to create real websites with all the issues, especially nice UX for your IHM.

Nevertheless, I selected 2 impressive projects that show Dash extraordinary potential. It is sure that it can be a strong alternative to a PHP framework like Symfony or Laravel to create an in-house CMS like the one I am dealing with for instance as it integrates like a charm Data Science features.

Files examples from my github account

001_plotly_interactive_webapps_dash.py
002_plotly_interactive_webapps_dash.py
003_interactive_webapps_dash.py
003_plotly_interactive_webapps_dash.py
004_interactive_webapps_dash.py
005_interactive_webapps_dash.py
006_interactive_webapps_dash.py
007_interactive_webapps_dash.py
008_interactive_webapps_dash.py
009_interactive_webapps_dash.py

The 2 great projects that leverage on Dash:

Conclusion
Regarding what I was looking for, I’d rather go with Streamlit. That is great tool to extend life to some of my python scripts transforming them into an application that is sharable with anyone including customers. The existence of a Framework like Streamlit greatly facilitates the design and creation of a web application. It makes a serious alternative to all frameworks and already appeals to more than one team or PO. Obviously, this is not just a fad as it might have been in its days RoR for instance.

More infos