Unlocking the Power of Streamlit: Building Web Apps in Minutes

Posted on Sep 18, 2023 • 3 min read

Priyank Kotak

Data Engineer

Unlocking the Power of Streamlit: Building Web Apps in Minutes

What is Streamlit?

Streamlit is an open-source Python library that simplifies the process of building web applications. It is designed to be beginner-friendly and allows you to turn your data scripts into shareable web apps effortlessly. With Streamlit, you can create interactive data visualizations, reports, and dashboards using Python and a few lines of code.

Getting Started with Streamlit

Installation:

Before you start building your Streamlit Web App, make sure you have Streamlit installed. 

You can install it using pip: pip install streamlit

Running My First Web App:

MyApp.py (Note: First install required libraries using “pip”)

import streamlit as st
import matplotlib.pyplot as plt

# Title
st.title("My Streamlit Blog")

# Author
st.write("Author: Priyank Kotak")

# Introduction
st.header("Introduction")
st.write("This is the introduction to my blog post. In this article, we will explore Streamlit and its capabilities.")

# Section 1
st.header("Section 1: Getting Started with Streamlit")
st.write("Streamlit is a Python library that allows you to create web applications for data science and machine learning projects with ease.")

# Code example
st.subheader("Code Example: Hello, Streamlit!")
st.code("""
import streamlit as st

st.title("Hello, Streamlit!")
st.write("This is a simple Streamlit app.")
""", language="python")

# Section 2
st.header("Section 2: Building a Streamlit App")
st.write("You can build Streamlit apps by combining widgets, text, and charts. It's a great way to create interactive data applications.")

# Create some sample data for the charts
data = {
'Categories': ['A', 'B', 'C', 'D'],
'Values': [30, 45, 15, 10]
}

# Create two columns for layout
left_column, right_column = st.columns(2)

# Add the pie chart to the left column
with left_column:
st.subheader('Pie Chart')
labels = data['Categories']
sizes = data['Values']
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
st.pyplot(fig1)

# Add the bar chart to the right column
with right_column:
st.subheader('Bar Chart')
categories = data['Categories']
values = data['Values']
fig2, ax2 = plt.subplots()
ax2.bar(categories, values)
plt.xlabel('Categories')
plt.ylabel('Values')
st.pyplot(fig2)

# Conclusion
st.header("Conclusion")
st.write("In conclusion, Streamlit is a powerful tool for creating web apps with Python, and it's especially useful for data professionals.")

Running Your Streamlit App:

Save the script and run it using the following command:

streamlit run your_script.py (In my case: streamlit run MyApp.py)

This will launch a local development server, and a new tab will open in your web browser, displaying your Streamlit App.

Output:

test

Key takeaways about Streamlit:

  • Ease of Use: 

    • Streamlit is known for its simplicity and user-friendliness. You can create a web app or dashboard with just a few lines of Python code. It's designed to be accessible to both beginners and experienced developers.

  • Python-Centric: 

    • If you're already familiar with Python, you don't need to learn new languages or frameworks to create web applications. You can leverage your existing Python skills to build interactive web apps.

  • Wide Range of Use Cases: 

    • Streamlit is versatile and can be used for various applications, including data visualization, machine learning model deployment, data exploration, and reporting.

  • Integration with Data Libraries: 

    • It easily integrates with popular data libraries like Pandas, Matplotlib, Plotly, and Seaborn, allowing you to visualize and manipulate data seamlessly.

  • Customization: 

    • Streamlit also offers customization options for those who want to fine-tune the appearance and behavior of their apps. You can include custom CSS, JavaScript, and HTML when needed.

  • Sharing and Deployment:

    • You can share Streamlit apps with others by simply sharing a URL or deploying them to cloud platforms like Heroku, AWS, or Streamlit Sharing. This makes it accessible to a wide audience.

  • Interactive Widgets: 

    • Streamlit provides a variety of widgets like sliders, buttons, and text inputs, making it easy to create interactive elements within your apps.

  • Open Source:

    • Streamlit is open-source, which means it's free to use and has an active community contributing to its development and improvement.

Conclusion

In summary, Streamlit's combination of simplicity, power, and flexibility has made it a valuable tool in the toolkit of data professionals, making it easier than ever to create engaging and interactive web applications without the need for extensive web development expertise. Whether you're a data scientist looking to visualize your findings or a content creator sharing insights with a broader audience, Streamlit offers an efficient and effective way to bring your data to life on the web.

AWS Certified Team

Tech Holding Team is a AWS Certified & validates cloud expertise to help professionals highlight in-demand skills and organizations build effective, innovative teams for cloud initiatives using AWS.

By using this site, you agree to thePrivacy Policy.