🔥 Streamlit Cheat Sheet – All You Need to Know! 🔥
🖥️ 1. Display Elements – Present Your Content
Function |
Purpose |
st.title("🚀 My App") |
Big bold title |
st.header("📌 Section Header") |
Medium header |
st.subheader("🔖 Sub Section") |
Small header |
st.text("Just plain text") |
Simple text |
st.markdown("**Bold** _Italic_") |
Supports rich formatting |
st.code("print('Hello')") |
Show code block |
st.latex(r"\alpha^2 + \beta^2 = \gamma^2") |
LaTeX equations |
st.write(obj) |
Smart auto-display: text, chart, dataframe, etc. |
🧠 2. User Input Widgets – Make Your App Interactive 🧩
Widget Type |
Function |
🔘 Button |
st.button("Click me!") |
☑️ Checkbox |
st.checkbox("I agree") |
🔄 Radio |
st.radio("Choose:", ["A", "B", "C"]) |
⬇️ Selectbox |
st.selectbox("Pick one", ["X", "Y"]) |
🧾 Multiselect |
st.multiselect("Choose options", [...]) |
🎚 Slider |
st.slider("Select a range", 0, 100) |
🧮 Number |
st.number_input("Enter number", min_value=0) |
🗒 Text input |
st.text_input("Enter name") |
📝 Text area |
st.text_area("Feedback") |
📅 Date |
st.date_input("Pick a date") |
⏰ Time |
st.time_input("Pick time") |
📁 File upload |
st.file_uploader("Upload a file") |
🎨 Color |
st.color_picker("Pick a color") |
🎥 3. Media Display – Add Life to Your App 🌠
Type |
Function |
🖼️ Image |
st.image("image.png") |
🔊 Audio |
st.audio("audio.mp3") |
🎥 Video |
st.video("video.mp4") |
📊 4. Data & Chart Display – Data Made Beautiful 📈
Data |
Chart |
📋 DataFrame |
st.dataframe(df) (scrollable + interactive) |
📑 Table |
st.table(df) (static) |
🧾 JSON |
st.json(data) |
🧮 Metric |
st.metric("Revenue", "$10K", "+5%") |
📈 Built-in Chart Types:
Chart |
Function |
📉 Line |
st.line_chart(df) |
📊 Bar |
st.bar_chart(df) |
🌄 Area |
st.area_chart(df) |
📊 External Libraries:
Library |
Function |
🎨 Matplotlib |
st.pyplot(fig) |
🧬 Altair |
st.altair_chart(chart) |
🧠 Plotly |
st.plotly_chart(fig) |
🎯 Bokeh |
st.bokeh_chart(fig) |
🔗 Graphviz |
st.graphviz_chart(graph) |
🌍 Maps |
st.map(df) |
🧩 5. Layout Functions – Design Like a Pro 🎨
Layout |
Function |
📍 Sidebar |
st.sidebar.xyz() → add any widget in sidebar |
📦 Container |
with st.container(): |
🪟 Expander |
with st.expander("See more"): |
🧱 Columns |
col1, col2 = st.columns(2) |
🗂 Tabs |
tab1, tab2 = st.tabs(["A", "B"]) |
🪄 Empty |
placeholder = st.empty() → for dynamic content |
⏳ Spinner |
with st.spinner("Loading..."): |
🍞 Toast |
st.toast("Success!", icon="✅") |
⚙️ 6. Control Flow & Caching – Add Logic 🔄
Feature |
Function |
✅ Stop execution |
st.stop() |
🔁 Rerun app |
st.experimental_rerun() |
📦 Cache data |
@st.cache_data |
🧠 Cache model/resource |
@st.cache_resource |
🧰 Session state |
st.session_state["key"] = value |
📂 7. File Handling – Upload & Download Files 📤📥
Task |
Function |
Upload |
st.file_uploader("Upload your doc") |
Download |
st.download_button("Download", data) |
🎨 8. Customize Look & Feel – Make It Yours ✨
Task |
Function |
Set page config |
st.set_page_config(page_title="My App", layout="wide", page_icon="🌟") |
Add config file |
~/.streamlit/config.toml (for global settings) |
✅ Pro Tip: Use st.write()
as your all-in-one function — it can render text, Markdown, charts, maps, DataFrames, and more!