| name | streamlit-1-basic-application-structure |
| description | Sub-skill of streamlit: 1. Basic Application Structure (+1). |
| version | 1.0.0 |
| category | data-analysis |
| type | reference |
| scripts_exempt | true |
1. Basic Application Structure (+1)
1. Basic Application Structure
Minimal App (app.py):
import streamlit as st
import pandas as pd
import polars as pl
st.set_page_config(
page_title="My Data App",
page_icon="📊",
layout="wide",
initial_sidebar_state="expanded"
)
st.title("My Data Application")
st.header("Welcome to the Dashboard")
st.subheader("Data Analysis Section")
st.text("This is plain text")
st.markdown("**Bold** and *italic* text with [links](https://streamlit.io)")
st.caption("This is a caption for additional context")
st.code("print('Hello, Streamlit!')", language="python")
df = pd.DataFrame({
"Name": ["Alice", "Bob", "Charlie"],
"Age": [25, 30, 35],
"City": ["NYC", "LA", "Chicago"]
})
st.dataframe(df)
st.table(df)
st.json({"key": "value", "list": [1, 2, 3]})
col1, col2, col3 = st.columns(3)
col1.metric("Revenue", "$1.2M", "+12%")
col2.metric("Users", "10,234", "-2%")
col3.metric("Conversion", "3.2%", "+0.5%")
Run the app:
streamlit run app.py
2. Widgets and User Input
Input Widgets:
import streamlit as st
from datetime import datetime, date
name = st.text_input("Enter your name", value="User")
bio = st.text_area("Tell us about yourself", height=100)
password = st.text_input("Password", type="password")
age = st.number_input("Age", min_value=0, max_value=120, value=25, step=1)
price = st.slider("Price Range", 0.0, 100.0, (25.0, 75.0))
rating = st.slider("Rating", 1, 5, 3)
option = st.selectbox("Choose an option", ["Option A", "Option B", "Option C"])
options = st.multiselect("Select multiple", ["Red", "Green", "Blue"], default=["Red"])
radio_choice = st.radio("Pick one", ["Small", "Medium", "Large"], horizontal=True)
agree = st.checkbox("I agree to the terms")
toggle = st.toggle("Enable feature")
selected_date = st.date_input("Select a date", value=date.today())
date_range = st.date_input(
,
value=(date(, , ), date.today()),
=
)
selected_time = st.time_input()
uploaded_file = st.file_uploader(, =[, ])
uploaded_file :
df = pd.read_csv(uploaded_file)
st.write()
color = st.color_picker(, )
st.button():
st.write()
():
pd.DataFrame({: [, , ], : [, , ]})
csv = get_data().to_csv(index=)
st.download_button(
label=,
data=csv,
file_name=,
mime=
)