Using Streamlit for Building Data Science Applications
๐ Using Streamlit for Building Data Science Applications
๐ง What Is Streamlit?
Streamlit is an open-source Python library that allows data scientists and machine learning engineers to:
Quickly turn data scripts into interactive web apps
Build custom dashboards, visualizations, and ML model interfaces
Do it all with pure Python — no need to know HTML, CSS, or JavaScript
✅ Perfect for prototyping, presenting results, and creating data tools
๐ฏ Why Use Streamlit?
Feature Benefit
๐งฉ Easy to use Write apps using regular Python scripts
⚡ Fast development From idea to app in minutes
๐ Interactive widgets Add sliders, buttons, dropdowns with one line
๐ Web-based sharing Deploy apps and share links with others
๐ง ML & data science-friendly Built for Jupyter-to-app workflows
๐ ️ How to Use Streamlit – Step by Step
✅ 1. Install Streamlit
Install it using pip:
pip install streamlit
✅ 2. Create a Python Script
Let’s build a simple app to visualize some data:
# file: app.py
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
st.title("๐ Simple Data Explorer")
# Load data
df = pd.read_csv("your_dataset.csv")
# Show dataset
st.subheader("Raw Data")
st.write(df.head())
# Add filter
selected_column = st.selectbox("Choose a column to plot", df.columns)
# Plot
st.subheader("Histogram")
fig, ax = plt.subplots()
df[selected_column].hist(ax=ax)
st.pyplot(fig)
✅ 3. Run Your App
In your terminal, run:
streamlit run app.py
A browser window will open with your interactive app!
๐งช Add Machine Learning to Your Streamlit App
Example: Load a trained model and let users input values for prediction.
import joblib
import numpy as np
model = joblib.load("model.pkl")
st.title("๐ Predict House Price")
# User input
sqft = st.slider("Square Footage", 500, 5000, 1500)
bedrooms = st.selectbox("Bedrooms", [1, 2, 3, 4, 5])
# Predict
if st.button("Predict"):
features = np.array([[sqft, bedrooms]])
prediction = model.predict(features)
st.success(f"Estimated Price: ${prediction[0]:,.2f}")
๐งฐ Common Use Cases in Data Science
Use Case Example Features
Data exploration Upload files, filter data, plot graphs
ML model demo Input fields for user data, show prediction results
Dashboard creation KPIs, charts, and metrics from live or batch data
Data preprocessing tools Let users clean or transform data interactively
Internal tools for teams Build quick utilities to support analysis or decision-making
๐ Share Your App
You can deploy your app:
Using Streamlit Community Cloud
(free, for public projects)
On platforms like Heroku, AWS, or Docker
๐ Summary
Feature Benefit
✅ Pure Python No web dev skills needed
๐ Fast prototyping Build and test data tools in minutes
๐ฏ ML-ready Great for showcasing models and analytics
๐ Easy sharing Deploy online and share with your team or users
๐ก Final Thought
Streamlit bridges the gap between notebooks and user interfaces.
It’s one of the simplest, fastest, and most Pythonic ways to build and share interactive data science applications.
Learn Data Science Course in Hyderabad
Read More
How Docker and Kubernetes Help in Data Science Deployment
Introduction to FastAPI for Data Science Applications
How to Use Apache Spark for Big Data Analytics
Why Scikit-learn is the Best ML Library for Beginners
Visit Our Quality Thought Training Institute in Hyderabad
Comments
Post a Comment