Deploying and Sharing Streamlit Application with Heroku and Streamlit
How to streamline as much as possible an application building process from conception to sharing… I am definitely addicted to Streamlit. So, for the coming months, I believe that Streamlit will be on top of any simple web-application that I will build for my own use both for Machine Learning webapps or for simple “facilitation” that how I call the webapps devoted to automation, visualization or data exploration!
Tired of reading a post, you can find the code and the videos directly on my GitHub account at the URLs below:
- https://github.com/bflaven/deploy-a-streamlit-app-with-heroku
- https://github.com/bflaven/deploy-a-streamlit-app-on-streamlit
So, to speak, as a PO, I have learned awkwardly but surely how to forge my own tools with this stated objective: delegate most of my work to computers, truly. That is the main motivation to learn computer language like Python. Especially learning Python gives access to a tremendous number of extended data-science features that seems to be unreachable in other language like PHP for instance. Indeed, for the last months, tooling has been my real job! On one hand, I am patiently adding new skills to my resume and the other hand, it jeopardizes some of the tools I am working on professionally. Let’s speak frankly, if these tools cannot aggregate new functionalities e.g. data visualization, NLP features for instance… They are doomed to disappear or me at least to stop working on it!
That is the reason why I have the lingering impression that continue to learn PHP, WordPress or even a framework like Symfony is like beating a dead horse… But, this is just my opinion.
Let’s get back on more basic question. First of all, as a user I need to be able to develop and then deploy locally and sometimes remotely these future tools, so they become sharable. You can even think about using Docker but I will focus only on 2 existing hosting platforms: Heroku and Streamlit itself. One thing at a time.
If you are interested by using Docker for your Streamlit apps, this post is a great and simple how-to.
- Getting Started with Streamlit (Streamlit Container)
https://containds.com/desktop/tutorials/getting-started-streamlit/
By sharing, I mean more than just sharing the information, it is sharing the product/tool itself.
Like many people, I have found that the easiest way to share a python app made with Streamlit as I have already set my sights on it are to deploy on these 2 platforms: Heroku and Streamlit as these platforms both offer hosting for free.
Let’s start by deploying an app on Heroku and then on Streamlit itself.
By the way, it was also the occasion to use directly Git in the mac console. So, let see first the requirements:
- Install Homebrew locally and make it accessible through the Mac console (Free) at https://brew.sh/
- Install Git locally and make it accessible through the Mac console (Free) at https://git-scm.com/download/mac
- Create an account on Github (Free) at https://github.com/
- Create an account on Heroku (Free) at https://signup.heroku.com/
- Create an account on Streamlit (Free) at https://share.streamlit.io/
First of all, it requires an account on Heroku, streamlit and Github. All these platforms are free so you can subscribe without fees. Just to let you know, there is a limitation both for in the app number and in the app build attempts. It requires also Git and Heroku CLI.
To install Git with homebrew
# It supposed that Homebrew is already installed on your computer. # https://brew.sh/ # to launch the Homebrew install, you can run the following command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # It supposed that Git is already installed on your computer. # Launch the install with homebrew brew install git # Check in the console with this command git --version # If Git is not installed, please do install it whith homebrew |
1. Deploying streamlit application on Heroku platform
In this step you’ll install the Heroku Command Line Interface (CLI). You use the CLI to manage and scale your applications, provision add-ons, view your application logs, and run your application locally.
# install Heroku Command Line Interface (CLI) brew doctor brew update brew install heroku/brew/heroku heroku autocomplete # Check in the console with this command heroku --version # https://docs.brew.sh/Shell-Completions |
So, you are ready to deploy on Heroku, you just have to create an Streamlit app on a GitHub repository that part is explained in the video below and the readme is available on my GitHub account.
2. Deploying streamlit application on Streamlit platform
Same workflow to deploy on Streamlit and same limitations for free account, you are limited in the number of applications you can deploy.
You will leverage on the same environment: git, GitHub repository for the Streamlit code. This part is also explained in the video below and the readme is available on my GitHub account.
Videos
If you want to see videos instead of reading a post, I have released 5 videos that explain what I intend to do. As Richard Feynman said “If you cannot explain something in simple terms, you don’t understand it.” that what prevailed during the videos creation.
- Video #1 Part 1 – Streamlit application requirements and installation
- Video #2 Part 2 – Install modules in your development environment and launch the Streamlit application
- Video #3 Part 3 – Using Git in the Mac Console to update your Streamlit application
- Video #4 Part 4 – Connect to Heroku with Heroku CLI & deploy your Streamlit application
- Video #5 Part 5 – All-in-one on deploying your Streamlit application on Streamlit’s platform
Conclusion
I guess a mix of shared app and an extensive Docker usage if needed can be a great hybrid solution to forge and share your own tools. The downside is that it requires a large amount of time as it is a time-consuming investigation as a PO to manage tools such as Docker, Git… etc. The return on time invested is worth as:
– It may save time later in your PO function
– It make also you resume more appealing (I will not dare to say sexy) as you show some interest for technologies that already shape your work. What I called the “follow the cash” method.
More infos
- How to Share Streamlit Apps Securely with Clients
https://towardsdatascience.com/sharing-streamlit-apps-securely-with-your-clients-a34bf0f9e00c - Turn An Excel Sheet Into An Interactive Dashboard Using Python (Streamlit)
https://www.youtube.com/watch?v=Sb0A9i6d320 - Python & VBA, Become an Office Superhero
https://pythonandvba.com/ - The Sven-Bo github account who is behind Python & VBA
https://github.com/Sven-Bo?tab=repositories - Deploying a Simple Streamlit app using Docker
https://www.section.io/engineering-education/how-to-deploy-streamlit-app-with-docker/ - How to Deploy Streamlit Apps with Docker
https://blog.jcharistech.com/2020/01/08/how-to-deploy-streamlit-apps-with-docker/ - Run Streamlit With Docker and Docker-Compose
https://dev.to/sophiabrandt/run-streamlit-with-docker-and-docker-compose-15d - Use a Different Volume For Your Docker Images in Ubuntu
https://medium.com/clusterfk/use-a-different-volume-for-your-docker-images-in-ubuntu-4c0315be6d66
- Making Docker, Conda and Jupyter play well together
https://towardsdatascience.com/making-docker-and-conda-play-well-together-eda0ff995e3c - Install Docker Desktop on Mac
https://docs.docker.com/desktop/mac/install/