๐ Streamlit for Beginners โ Complete Guide with Examples
Streamlit is a powerful Python library used to create interactive web applications for Data Science, Machine Learning, and Automation โ all with just Python. No need for HTML, CSS, or JavaScript!
Written By: Nivesh Bansal Linkedin, GitHub, Instagram
๐ฅ What is Streamlit?
Library Name: Streamlit
Purpose: Convert Python scripts into interactive web apps
Installation:pip install streamlit
Run Command:streamlit run your_script.py
Who Uses It: Data Scientists, ML Engineers, Analysts
Frontend Code Needed: None โ only Python
โ Step-by-Step Streamlit Guide
๐ 1. Installation
pip install streamlit
Check if it's working:
streamlit hello
๐ 2. Run a Streamlit App
streamlit run your_script.py
๐ฅ 3. Display Text in UI
-
st.title("Title")โ Displays a big page title -
st.header("Header")โ Section heading -
st.subheader("Subheader")โ Subsection heading -
st.text("Plain text")โ For normal text -
st.markdown("*Bold* and _Italic_")โ Markdown formatting -
st.code("print('Hello')")โ Code block -
st.latex(r"x^2 + y^2 = z^2")โ Math equation
โ 4. Take User Inputs
-
st.text_input("Name"): Text input -
st.number_input("Age"): Number input -
st.text_area("About"): Multi-line input -
st.date_input("Date"): Date picker -
st.time_input("Time"): Time picker -
st.selectbox("Select", options): Dropdown -
st.radio("Choose", options): Radio buttons -
st.multiselect("Pick", options): Multi-select -
st.slider("Slide", min, max): Slider -
st.file_uploader("Upload"): File uploader -
st.checkbox("I Agree"): Checkbox -
st.button("Submit"): Button -
st.color_picker("Color"): Color picker
๐ 5. Display Charts and Data
-
st.dataframe(df): Interactive table -
st.table(df): Static table -
st.metric("Speed", "100 km/h"): Display key metric -
st.line_chart(df): Line chart -
st.bar_chart(df): Bar chart -
st.area_chart(df): Area chart -
st.pyplot(fig): Matplotlib chart -
st.map(df): Map using lat/long
๐ 6. Media Display
st.image("img.jpg") # Show image
st.video("video.mp4") # Play video
st.audio("audio.mp3") # Play audio
โ 7. Progress and Status
st.progress(50) # Show a progress bar
st.spinner("Loading...") # Show loading spinner
st.success("Done!") # Green success message
st.error("Something went wrong") # Red error message
st.warning("Be careful!") # Yellow warning
st.info("FYI...") # Blue info box
๐ง 8. Caching
@st.cache_data
def load_data():
return some_heavy_function()
๐ฌ 9. Sidebar Navigation
st.sidebar.title("Menu")
page = st.sidebar.selectbox("Choose Page", ["Home", "About"])
๐พ 10. Session State
if "count" not in st.session_state:
st.session_state.count = 0
if st.button("Increase"):
st.session_state.count += 1
st.write("Count:", st.session_state.count)
๐งช Full App Example
import streamlit as st
st.title("๐ Hello Streamlit App")
name = st.text_input("Enter your name:")
if st.button("Submit"):
st.success(f"Hello, {name}!")
๐ Official Resources
- ๐ Streamlit Docs
- ๐ Streamlit GitHub
โ Summary
- Build full UI using Python only
- No frontend coding needed
- Supports charts, media, files, inputs, and session memory
- Great for fast dashboards or ML apps
๐ฏ Project Ideas
- ๐ Stock Price Viewer
- ๐ฆ๏ธ Weather Forecast App
- ๐งโ๐ Student Registration Form
- ๐ CSV Data Visualizer
- ๐ง MCQ Quiz Generator
๐ก Want full source code for any of the projects above? Just drop a comment and Iโll reply with the source and setup guide.
Written By: Nivesh Bansal Linkedin, GitHub, Instagram
Top comments (0)