๐ฏ Streamlit for Data Apps — Build Dashboards in 10 Lines of Python
Tired of HTML and JS? Streamlit lets you create interactive dashboards with pure Python — no frontend code required! From charts to file uploads to ML model demos — it’s all possible in minutes. Let’s dive into the world of Streamlit! ๐
1️⃣ Install Streamlit
!pip install streamlit
Then launch the app with:
streamlit run app.py
Just check in your terminal prompt cmd: python -m streamlit hell
2️⃣ Your First Streamlit App (10 Lines Only)
import streamlit as st
import pandas as pd
import numpy as np
st.title("๐ My First Streamlit Dashboard")
st.write("Hello, Data Scientists! ๐")
data = pd.DataFrame(np.random.randn(10, 2), columns=["A", "B"])
st.line_chart(data)
Run it and open the browser link — boom ๐ฅ an interactive chart in seconds!
It it does not work, try in your project folder cmd prompt: python -m pip install --upgrade streamlit && python -m streamlit run t1.py
3️⃣ Adding Widgets
import streamlit as st
st.title("๐️ Widgets in Action")
name = st.text_input("Enter your name:")
age = st.slider("Select your age", 10, 60, 25)
clicked = st.button("Greet Me")
if clicked:
st.success(f"Hey {name}, you are {age} years old! ๐")
๐ Streamlit automatically handles UI, state, and interactivity — no callbacks needed!
4️⃣ Displaying DataFrames and Charts
import streamlit as st
import pandas as pd
import plotly.express as px
st.title("๐ Visualizing Data with Plotly")
df = px.data.gapminder().query("year == 2007")
continent = st.selectbox("Choose Continent", df["continent"].unique())
filtered_df = df[df["continent"] == continent]
fig = px.bar(filtered_df, x="country", y="gdpPercap", color="country", title=f"GDP per Capita in {continent}")
st.plotly_chart(fig)
5️⃣ File Upload Example
import streamlit as st
import pandas as pd
st.title("๐ CSV File Uploader")
file = st.file_uploader("Upload your CSV file", type=["csv"])
if file:
df = pd.read_csv(file)
st.write("Preview:")
st.dataframe(df.head())
Perfect for quick data exploration dashboards ๐
6️⃣ Real-Time Metrics Dashboard
import streamlit as st
import numpy as np
import time
st.title("๐ Real-Time Metrics Dashboard")
progress = st.progress(0)
status = st.empty()
for i in range(100):
progress.progress(i + 1)
status.text(f"Processing... {i + 1}%")
time.sleep(0.05)
st.success("✅ Done!")
Part of Result
7️⃣ Deploy to the Web (Free!)
๐ Host your app free on Streamlit Cloud — just connect your GitHub repo and click “Deploy”.
It auto-runs your streamlit run app.py on the cloud ๐
✅ What You Learned
- ๐ก Create dashboards in pure Python
- ๐จ Add charts, forms, and widgets easily
- ๐ฆ Upload and visualize data
- ๐ Deploy in minutes with Streamlit Cloud
Bro, now you can build a full-fledged **AI or ML dashboard** in under 30 lines of code ๐ Next step? Try connecting Streamlit with your trained ML model for live predictions!
No comments:
Post a Comment