Tuesday, 21 October 2025

#8 Streamlit interactive dashboards

๐ŸŽฏ 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

#21a Dunder Method - Samples

Python Dunder (Magic) Methods – Complete Guide with Demos Python Dunder (Magic) Methods – Complete Guide with Demos ...