Summary

Expanding on streamlit's tutorial, I created a streamlit app on heroku.

Interlude

It has been a tough couple of weeks for me to grapple with events that unfolded about 30 minutes away from where I live. This Martin Luther King Jr. quote that I read on Chris Damian's blog post resonated with me:

“Let me say as I’ve always said, and I will always continue to say, that riots are socially destructive and self-defeating. … But in the final analysis, a riot is the language of the unheard. And what is it that America has failed to hear? It has failed to hear that the plight of the Negro poor has worsened over the last few years. It has failed to hear that the promises of freedom and justice have not been met. And it has failed to hear that large segments of white society are more concerned about tranquility and the status quo than about justice, equality, and humanity. And so in a real sense our nation’s summers of riots are caused by our nation’s winters of delay. And as long as America postpones justice, we stand in the position of having these recurrences of violence and riots over and over again.”

Excerpt from Martin Luther King Jr.’s speech “The Other America,” 1967 at Stanford University.

Curious on the context of the quote, I ended up listening to the whole speech on YouTube:

I hope that the words of MLK Jr. provided a context on the institutional racism that pervades the world in which we live in. May we have a more just and kind society.

Introduction

I first heard about streamlit from a data scientist in the area. Supposedly, it can create an interactive web python app in a simplified manner. So, I went ahead and run through the tutorial to understand more on its capability. Since I am familiar with flask, I am going to compare it with streamlit in this introduction.

First off, compared to flask, streamlit is simpler when it comes to creating a dynamic web app. In flask, it is recommended to save the python file in .py files in root and the html file in .html files in templates folder. This is partly due to html being a verbose markup language. On the other hand, streamlit uses GitHub flavored markdown and both python and markdown co-exist in one single python file. Markdown syntax can render rich formatted content in a concise manner. Of course, combining python with markdown texts can be confusing at first. But, if one is already familiar with jupyter notebook, this format should come naturally.

Streamlit is created with fast deployment in mind. If one wants to have a perfect platform with all the bells and whistles, flask and django should be considered. However, if we want to keep things simple and get quick feedback from other teams, streamlit should be the way to go.

With that in mind, let's get to the streamlit tutorial.

Streamlit tutorial

My streamlit tutorial is deployed on heroku. The tutorial can be loosely divided into:

  1. Interactive DataFrame
  2. Drawing charts and maps
  3. Add interactivity with Widgets
  4. Show progress
  5. Record a screencast

Feel free to take a look at the github repository to look into the tutorial_streamlit.py Python code.

Heroku deployment

For deploying the streamlit code into heroku, I followed along this YouTube video:

However, there are two deviations from the video:

  1. For the virtual environment, using my old pyenv resulted in heroku crashing during the deployment. So, I created a new pyenv specifically to deploy the streamlit to heroku.
  2. For my setup.sh, I stripped away all the backslashes and the newline characters as recommended on the streamlit's forum:
    mkdir -p ~/.streamlit
    echo "[server]  
    headless = true  
    port = $PORT  
    enableCORS = false  
    " > ~/.streamlit/config.toml

Concluding thoughts

Streamlit package is a simple way to deploy data driven app on the internet. I am excited to use this in creating a nice interactive machine learning web app in the future!