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)