π 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)