DEV Community

Cover image for Streamlit Beginner Guide with Examples
Nivesh Bansal
Nivesh Bansal

Posted on • Edited on

Streamlit Beginner Guide with Examples

πŸš€ 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

βœ… 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)