Data Science is one of the most trending search topics on google these days. Because of its high demand and exhaustive usage in real-world applications, more and more developers in the community are developing new frameworks and libraries that help data scientists and researchers complete everyday tasks. One such library is streamlit. With streamlit, one can build data apps in no time. It seamlessly integrates with other python libraries like NumPy, Pandas, Matplotlib, and many more.
Streamlit is a Python-based library that allows data scientists to easily create free machine learning applications. You can easily read in a saved model and interact with it with an intuitive and user friendly interface. It allows you to display descriptive text and model outputs, visualize data and model performance, modify model inputs through the UI using sidebars and much more. It is an easy-to-learn framework that allows data science teams to create free predicitve analytics web applications in as little as a few hours.
It doesn’t take long to start developing with Streamlit, since you don’t even need any front-end web development experience. With Streamlit, you script everything with Python. Streamlit is also compatible with data science libraries.
Streamlit is a Python application, which means all the typical methods (EC2, containers etc.) used to host a Python app are valid for Streamlit as well.
Streamlit requires python >= 3.7 version in your machine.
To install streamlit, you need to run the command below in the terminal :
pip install streamlit
You can also check the version installed on your machine with the following command :
After successfully installing streamlit, you can test the library by running the command below in the terminal :
Streamlit’s Hello app will appear in a new tab in your web browser. This shows that everything is running ok, we can move on and create our first web app by using Streamlit.
Advantages of using streamlit
A few of the advantages of using Streamlit tools like Dash and Flask:
- It embraces Python scripting; No HTML knowledge is needed!
- Less code is needed to create a beautiful application
- No callbacks are needed since widgets are treated as variable
- Data caching simplifies and speeds up computation pipelines.
Streamlit has a lot of APIs to support different representations and much can be written about each types and considerations related to them; but we will get started with 3 basic APIs which are very strong to start writing the apps. These are:
This api is used to create a title element in the data app. The title comes in bold and in the top of the app page. The title takes a string argument which it represents in the title position. This is a useful method to give a proper heading to your app.
This api is called the swiss army knife of streamlit. If you don’t know the variety of apis to write specific different things; then also you can use the st.write to print or show or display elements in your app using this method.
This api is useful for creating different sections in a very naive one-linear layout of an app. This creates big and bold texts out of its argument and displays them properly; hence helps in creating sections in your app.
Streamlit allows you to write an app the same way you write a python code. The streamlit has a distinctive data flow, any time something changes in your code or anything needs to be updated on the screen, streamlit reruns your python script entirely from the top to the bottom. This happens when the user interacts with the widgets like a select box or drop-down box or when the source code is changed.
If you have some costly operations while rerunning your web app, like loading data from databases, you can use streamlit’s st.cache method to cache those datasets, so that it loads faster.