Streamlit has emerged as a popular open-source app framework for Machine Learning and Data Science projects. It allows for the rapid development of interactive web applications with minimal coding. In this guide, we provide a practical walkthrough to help you get started with Streamlit, accompanied by real-world examples for a hands-on experience.

Introduction to Streamlit

Streamlit is a Python library that facilitates the easy creation of interactive web apps with just a few lines of Python code. It is particularly favored in the data science community for its simplicity and efficiency. Below, we delineate the initial steps to embark on your Streamlit journey.

Real-World Application:

In the real world, data scientists often use Streamlit to create dashboard applications where stakeholders can interactively explore data and insights.

Installing Streamlit

Getting started with Streamlit is remarkably straightforward. The first step is to install the library using the following command:

pip install streamlit

Step-by-Step Guide:

  1. Open your terminal or command prompt.
  2. Type the command mentioned above and hit Enter.
  3. Wait for the installation to complete, which usually takes a few moments.

Creating Your First Streamlit App

After the installation, creating a Streamlit app is as easy as writing a Python script. Here, we guide you through the creation of a simple Streamlit app.

import streamlit as st

st.title('My First Streamlit App')

st.write('Hello, Streamlit!')

Real-World Example:

Imagine creating a simple application for a local event where visitors can find basic information and greetings. This script serves as a stepping stone for such applications.

Running Your Streamlit App

To run your Streamlit app, use the following command in the terminal:

streamlit run your_script_name.py

Step-by-Step Guide:

  1. Save your script with a .py extension.
  2. Open the terminal and navigate to the directory where the script is saved.
  3. Run the command mentioned above.
  4. Your app will now be accessible in a web browser at localhost:8501.

Expanding Your Streamlit App

As you grow comfortable, you can start adding more functionalities to your Streamlit app. Streamlit offers a variety of widgets like sliders, buttons, and text inputs to make your app interactive.

st.slider('Select a range', 0.0, 100.0)

Real-World Example:

Consider a real estate web application where users can filter properties within a specific price range using a slider.

Real-World Application Examples with Streamlit

1. Installing Streamlit

Suppose a data science team in a corporate setting is planning to create a series of interactive dashboards to share insights and analytics with the management. To commence, each team member needs to install Streamlit on their systems. Following the steps outlined in the guide, they would be able to successfully set up Streamlit and be ready to start building the apps.

2. Creating Your First Streamlit App

Imagine a non-profit organization aiming to create a basic app to spread awareness about their cause. Using Streamlit, they can quickly develop an app with the following script, which displays a welcoming message and information about their mission:

import streamlit as st

st.title('Non-Profit Awareness App')

st.write('Welcome to our initiative where we aim to make a difference in society. Learn more about our mission and how you can contribute.')

This script serves as the foundation of their app, which they can later expand with more details and interactive elements.

3. Running Your Streamlit App

A group of students is tasked with creating a web application as part of their project assignment. They have created a Streamlit script named project_app.py that displays various visualizations based on a dataset. To present this app to their professor and classmates, they follow the steps in the guide to run the app. Consequently, they can access and demonstrate the app through a web browser, providing a seamless presentation experience.

4. Expanding Your Streamlit App

An eCommerce company wishes to create an internal tool for their sales team where they can monitor and analyze sales data interactively. Building upon the basic Streamlit app, they add various widgets like sliders and buttons to filter the data displayed based on different criteria such as date range and product categories. Here’s a snippet illustrating how a slider can be used to filter data based on a price range:

import streamlit as st

st.title('Sales Data Dashboard')

price_range = st.slider('Select a price range', 0, 1000)
st.write(f'Displaying products within the price range: ${price_range}')

# Here, code would be added to fetch and display data based on the selected price range.

Through Streamlit, they manage to create a functional and interactive tool that enhances the efficiency of the sales team.

Conclusion

These examples vividly demonstrate the versatility and utility of Streamlit in different real-world scenarios. From corporate settings to educational projects, Streamlit serves as a practical tool that enables the creation of interactive web applications with relative ease. As individuals or organizations progress, they can explore more advanced features of Streamlit to create more sophisticated and interactive applications tailored to their specific needs.

Streamlit stands as a potent tool in the toolkit of data scientists and developers looking to create interactive web applications with ease. As you delve deeper, you will discover more advanced features and functionalities that Streamlit has to offer. We recommend practicing by creating different types of applications and gradually incorporating more complex features to enhance your skills. Remember, the best learning is through doing, and with Streamlit, getting started has never been easier.

Processing…
Success! You're on the list.

Also Read:

Categorized in: