Streamlit, the easy way to build external data products

Jensbaekelmans
5 min readDec 19, 2022

--

I’m currently working as a Data Science Intern at the Data Intelligence company Collibra. As a Data Intern, my goal is to display the results of an analytical product with a tool that could be used by internal or external people. We have found a framework called Streamlit and took it under the loop. In this blog, you will find a summary of what Streamlit is, how you can make an app in minutes and how it compares against other frameworks.

What is Streamlit?

Streamlit is an open-source python library that makes it easy to make custom web applications. It was made to help Data Scientists and Machine Learning engineers to deploy their ML models and dashboards in a web-based environment without the need of learning web development frameworks. It was founded by ex-google engineers in 2018.

Streamlit is a low-code solution. But what does that mean? Low-code solutions are designed to make it easy for people to create applications without having to write a lot of code. They make sure that people can focus on creating applications instead of learning how to make them.

Let's start by creating your own Streamlit application.

How do you build your Streamlit app?

  1. Open your favourite code editor (e.g. VScode or Pycharm). Make a new python file called app.py. Open your code terminal and install Streamlit with the use of Pip install streamlit.
pip install streamlit

2. After installing, you import the Streamlit library by ‘import streamlit as st’ at the top of your file and you can start coding.

Import streamlit as st

3. Use st.write(‘Hello world’) to write your first code into the app.

st.write('Hello world')

4. After coding your application, it can be launched into your browser. Run the following code and see Streamlit in action.

Streamlit run app.py 

Only 4 steps are required to build a new web application. This makes Streamlit a very popular application for anyone who wants to deploy their dashboard or models.

Now you have seen how easy it is to build an application. Let's make one together to see what Streamlit is capable of doing.

Airbnb Visualization with Kepler.gl

Let's visualize the amount of Airbnb’s in the city of Antwerp in Belgium together. Find the free data set here. Download it on your device and let's start coding. Open your code editor of choice and follow the steps from above to install Streamlit. Pursue the next steps in order to recreate the following visual.

1. Pip install the following libraries: pandas, kepler.gl and streamlit_keplergl in your terminal. Afterwards, import to the top of your file and use st.header() and st.subheader() to write a small description of your app.

Pip install pandas
pip install kepler.gl
pip install streamlit_keplergl
st.header("This is an app that visualizes Airbnb data in Antwerp!")
st.subheader("A quick tutorial on how to use Streamlit!")

2. Use pandas to upload your file and read it into a data frame. Streamlit can automatically deploy data frames with st.dataframe().

df = pd.read_csv("http://data.insideairbnb.com/belgium/vlg/antwerp/2022-09-22/visualisations/listings.csv")

3. Create a map instance with keplergl and add your data frame to the map. Show it with keplergl_static().

map = KeplerGl(height=400)
map.add_data(df, name='Antwerpen Airbnb data')
keplergl_static(map)

4. The last step is to run your Streamlit app and see the magic happen.

import streamlit as st
import pandas as pd
from streamlit_keplergl import keplergl_static
from keplergl import KeplerGl

st.header('This is an app that visualizes Airbnb data in Antwerp!')
st.subheader('A quick tutorial on how to use Streamlit')

df = pd.read_csv("http://data.insideairbnb.com/belgium/vlg/antwerp/2022-09-22/visualisations/listings.csv")

map = KeplerGl(height=400)
map.add_data(df, name='Antwerpen Airbnb data')
keplergl_static(map)

How does Streamlit perform against other solutions?

The main competitors are Dash and R-Shiny. Other frameworks like Django and Flask are not discussed here. These are frameworks for building out a complete website from the ground up and this is different from our goal.

One of the main competitors is Dash. Dash is created by Plotly. Dash is an open-source Python library for creating interactive web applications. It allows you to create highly customizable and reactive data visualizations with minimal code. Dash apps can be used for a wide range of purposes, including data visualization and exploration. The library includes a variety of built-in components that you can use to create everything from simple graphs and charts to more complex and interactive elements like sliders and dropdown menus. Dash is designed to be easy to use and allows you to build an app quickly with less code. The app’s data and visualizations are automatically updated in real-time as users interact with your app.

Another solution is R-shiny for Python. Very famous for its initial version in the R language. R-Shiny for Python is a library for creating interactive web applications using Python. It allows you to create everything from simple data visualizations to more complex and interactive elements like sliders, dropdown menus, and text input boxes. Apps are built using Python, and the app’s code is executed on the server, which then sends the necessary data to the client. The application is in alpha at the moment (December 22) and is still too unstable to use in a production environment. However, it is compatible with multiple libraries. Streamlit still has our preference, because R-shiny is still in alpha and the simplicity of the application. A review is needed in future if the beta is a better product for our needs.

I added a table which compares all different frameworks on maturity, popularity, simplicity, adaptability and focus. This graph gives a good overview of all frameworks available and the differences between them all.

Source: Datarevenue.com

After multiple iterations of going through the documentation and reviews. The simplicity of building an application and at which speed we could show our finished product was the final deciding factor. Overall, Streamlit is a powerful and easy-to-use tool for creating interactive web applications with Python. Its simplicity and flexibility make it a good choice for developers who want to create sophisticated and powerful applications without having to spend a lot of time learning a complex framework.

This blog was written together with Alexandre T’Kint. My mentor and Data Scientist at Collibra. He guided me throughout the whole process from creating the Streamlit website to writing the blog.

--

--