Build and Deploy a Streamlit Sales Dashboard
A sales dashboard in Streamlit, from pip install to a public URL. It loads a CSV of store sales, adds month and year columns, shows each city’s sales against the previous year, and lets viewers pick a city and year for the monthly and category charts. Deployment to Streamlit Community Cloud is free.
Table of contents
Set up the app
Install Streamlit and pandas with pip install streamlit and pip install pandas, create a file called streamlit_app.py and import both libraries:
import streamlit as st
import pandas as pd
A page title and an icon are enough to check that everything works. The icon can be an emoji (Windows key and period opens the emoji picker on Windows). Start the app with streamlit run streamlit_app.py, and it opens in your default browser.
import streamlit as st
import pandas as pd
# --- PAGE SETUP ---
st.set_page_config(page_title="Sales Dashboard", page_icon="📈")
st.title("Sales Dashboard")
Load the data
The dataset is a CSV file on GitHub. I keep its URL in a configuration section at the top of the script, load it with pandas and show it with st.dataframe. After a refresh, the table appears in the browser.
import streamlit as st
import pandas as pd
# --- CONFIGS ---
DATA_URL = "https://raw.githubusercontent.com/Sven-Bo/datasets/master/store_sales_2022-2023.csv"
# --- PAGE SETUP ---
st.set_page_config(page_title="Sales Dashboard", page_icon="📈")
st.title("Sales Dashboard")
# --- LOAD DATA ---
data = pd.read_csv(DATA_URL)
st.dataframe(data)

If you want your own practice data, my free Excel dataset generator creates a sales table in seconds.
Add month and year columns
The charts need sales by month and year, so date_of_sale has to become a real date first. I work this out in a Jupyter notebook, where I can look at the data step by step, and copy the finished code into the app.
import pandas as pd
# Dataset URL
DATA_URL = "https://raw.githubusercontent.com/Sven-Bo/datasets/master/store_sales_2022-2023.csv"
# Load dataset
data = pd.read_csv(DATA_URL)
# Display the first few rows
data.head()
order_id product_id store_id product_name product_category city date_of_sale quantity_sold sales_amount
0 1 52 1 CodeComet Software Development Tools Tokyo 1/1/2022 8 303.29
1 2 83 3 SyntaxScribe Software Development Tools Yokohama 1/1/2022 8 173.53
2 3 24 3 CodeCanvas Software Development Tools Yokohama 1/2/2022 6 37.72
3 4 88 2 VarVista Pro Educational Tools Osaka 1/2/2022 6 10.47
4 5 60 1 LoopLantern Creative & Design Tools Tokyo 1/3/2022 1 159.10
The info method shows the data types and any missing values. Here date_of_sale is text, so pd.to_datetime converts it, and one assign call adds the month and year columns:
# Perform the same transformations using method chaining
data = data.assign(
date_of_sale=lambda df: pd.to_datetime(df['date_of_sale']),
month=lambda df: df['date_of_sale'].dt.month,
year=lambda df: df['date_of_sale'].dt.year
)
# Display the transformed DataFrame
data.head()
order_id product_id store_id product_name product_category city date_of_sale quantity_sold sales_amount month year
0 1 52 1 CodeComet Software Development Tools Tokyo 2022-01-01 8 303.29 1 2022
1 2 83 3 SyntaxScribe Software Development Tools Yokohama 2022-01-01 8 173.53 1 2022
2 3 24 3 CodeCanvas Software Development Tools Yokohama 2022-01-02 6 37.72 1 2022
3 4 88 2 VarVista Pro Educational Tools Osaka 2022-01-02 6 10.47 1 2022
4 5 60 1 LoopLantern Creative & Design Tools Tokyo 2022-01-03 1 159.10 1 2022
Year-over-year metrics
Group the sales by city and year, sum them, and put the years side by side with unstack. The percentage change from the previous year then becomes one more column.
YEAR = 2023
# Calculate total revenue for each city and year, then calculate percentage change
city_revenues = (
data.groupby(['city', 'year'])['sales_amount']
.sum()
.unstack()
.assign(change=lambda x: x.pct_change(axis=1)[YEAR] * 100)
)
city_revenues
year 2022 2023 change
city
Osaka 76914.92 81202.93 5.575004
Tokyo 79961.13 72717.66 -9.058739
Yokohama 63216.90 67110.89 6.159729
In the app, this table feeds three st.metric cards, one per city, with the change against the previous year as the delta. YEAR and the list of CITIES go into the configuration section at the top of the script:
# --- CONFIGS ---
YEAR = 2023
CITIES = ["Tokyo", "Yokohama", "Osaka"]
# --- KEY METRICS ---
# Display each city's data in separate columns
left_col, middle_col, right_col = st.columns(3)
with left_col:
st.metric(
label=CITIES[0],
value=f"$ {city_revenues.loc[CITIES[0], YEAR]:,.2f}",
delta=f"{city_revenues.loc[CITIES[0], 'change']:.2f}% vs. Last Year",
)
# City 2 in the middle column
with middle_col:
st.metric(
label=CITIES[1],
value=f"$ {city_revenues.loc[CITIES[1], YEAR]:,.2f}",
delta=f"{city_revenues.loc[CITIES[1], 'change']:.2f}% vs. Last Year",
)
# City 3 in the right column
with right_col:
st.metric(
label=CITIES[2],
value=f"$ {city_revenues.loc[CITIES[2], YEAR]:,.2f}",
delta=f"{city_revenues.loc[CITIES[2], 'change']:.2f}% vs. Last Year",
)
In the full script on GitHub, the loading and cleaning steps sit in one function decorated with @st.cache_data, so the CSV is downloaded once instead of on every click.
Add filters
A dropdown picks the city and a toggle switches between the current and the previous year. Streamlit reruns the script on every change, so the variables always hold the current selection.
# --- SELECTION FIELDS ---
# City & Year selection
selected_city = st.selectbox("Select a city:", CITIES)
show_previous_year = st.toggle("Show Previous Year")
if show_previous_year:
visualization_year = YEAR - 1
else:
visualization_year = YEAR
st.write(f"**Sales for {visualization_year}**")

Add charts
Two tabs show sales by month and sales by product category. In each, query filters the data to the selected city and year, groupby sums the sales, and st.bar_chart draws the result.
# Tabs for analysis type
tab_month, tab_category = st.tabs(["Monthly Analysis", "Category Analysis"])
# --- FILTER & VISUALIZE DATA ---
with tab_month:
filtered_data = (
data.query("city == @selected_city & year == @visualization_year")
.groupby("month", dropna=False, as_index=False)["sales_amount"]
.sum()
)
st.bar_chart(
data=filtered_data.set_index("month")["sales_amount"],
)
with tab_category:
filtered_data = (
data.query("city == @selected_city & year == @visualization_year")
.groupby("product_category", dropna=False, as_index=False)["sales_amount"]
.sum()
)
st.bar_chart(
data=filtered_data.set_index("product_category")["sales_amount"],
)
Hide the Streamlit header
A few lines of CSS in st.markdown with unsafe_allow_html=True hide the main menu and the header bar at the top.
# --- HIDE STREAMLIT BRANDING ---
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
The selectors change between Streamlit versions, so see how to hide the Streamlit header and menu if yours stop working.
Deploy for free
Push the script to a GitHub repository together with a requirements.txt that lists the packages the server must install. Then sign in to Streamlit Community Cloud, pick the repository, branch and main file, and click Deploy.


Two natural next steps: if your data lives in an Excel file, turn an Excel sheet into an interactive Streamlit dashboard, and when the app grows, split it into pages as shown in how to create a Streamlit multi-page app.
