Turn an Excel Sheet Into an Interactive Dashboard With Python (Streamlit)
pandas reads the Excel sheet, Plotly draws the charts, and Streamlit turns the script into a web dashboard: KPIs across the top, two bar charts below, and sidebar filters that drive both. Every filter change reruns the script, so the dashboard stays in sync without callbacks.

The dataset
The workbook supermarkt_sales.xlsx holds supermarket sales from three cities. Each row is one purchase, with the customer type, gender, product line, total including tax, time of purchase and a customer satisfaction rating. The table starts in cell B4 of the Sales sheet.

Install the libraries
The dashboard needs four packages: pandas and openpyxl to read the workbook, Plotly for the charts and Streamlit for the web app. Plotly Express ships with plotly, so no separate plotly-express package is needed.
pip install streamlit plotly
pandas and openpyxl install the same way: pip install pandas openpyxl.
Load the Excel data
pd.read_excel() reads the table into a DataFrame. Because the data starts in B4, the call skips the first three rows and reads columns B to R.
import pandas as pd # pip install pandas openpyxl
df = pd.read_excel(
io="supermarkt_sales.xlsx",
engine="openpyxl",
sheet_name="Sales",
skiprows=3,
usecols="B:R",
nrows=1000,
)
print(df)
In the video I generate this call with my Excel add-in MyToolBelt, which writes the read_excel code for a selected range. You can also type it yourself.
Streamlit reruns the whole script on every filter change, which would read the workbook again each time. Wrapping the read in a function with @st.cache_data loads it once and reuses the cached DataFrame. Older versions of this code use @st.cache, which current Streamlit no longer has. The function also adds an hour column from the Time column for the hourly chart.
@st.cache_data
def get_data_from_excel():
df = pd.read_excel(
io="supermarkt_sales.xlsx",
engine="openpyxl",
sheet_name="Sales",
skiprows=3,
usecols="B:R",
nrows=1000,
)
# Add 'hour' column to dataframe
df["hour"] = pd.to_datetime(df["Time"], format="%H:%M:%S").dt.hour
return df
df = get_data_from_excel()
Set up the page
st.set_page_config() sets the browser tab title and icon, and layout=”wide” uses the full width of the window. Call it at the top of the script.
import pandas as pd # pip install pandas openpyxl
import plotly.express as px # pip install plotly
import streamlit as st # pip install streamlit
st.set_page_config(page_title="Sales Dashboard", page_icon=":bar_chart:", layout="wide")
Sidebar filters
Three multiselect boxes in the sidebar filter the data by city, customer type and gender. Each one offers the unique values of its column and starts with all of them selected.
df.query() then keeps the rows that match all three selections. The @ in the query string refers to the Python variables that hold the selected values.
# ---- SIDEBAR ----
st.sidebar.header("Please Filter Here:")
city = st.sidebar.multiselect(
"Select the City:",
options=df["City"].unique(),
default=df["City"].unique()
)
customer_type = st.sidebar.multiselect(
"Select the Customer Type:",
options=df["Customer_type"].unique(),
default=df["Customer_type"].unique(),
)
gender = st.sidebar.multiselect(
"Select the Gender:",
options=df["Gender"].unique(),
default=df["Gender"].unique()
)
df_selection = df.query(
"City == @city & Customer_type ==@customer_type & Gender == @gender"
)
If the filters leave no rows, the charts would be empty. This check from the GitHub version goes right after df_selection, shows a warning and stops the script:
# Check if the dataframe is empty:
if df_selection.empty:
st.warning("No data available based on the current filter settings!")
st.stop() # This will halt the app from further execution.
KPIs
Three key figures sit across the top: total sales, the average rating with stars, and the average sale per transaction. st.columns(3) splits the row into three equal columns.
# ---- MAINPAGE ----
st.title(":bar_chart: Sales Dashboard")
st.markdown("##")
# TOP KPI's
total_sales = int(df_selection["Total"].sum())
average_rating = round(df_selection["Rating"].mean(), 1)
star_rating = ":star:" * int(round(average_rating, 0))
average_sale_by_transaction = round(df_selection["Total"].mean(), 2)
left_column, middle_column, right_column = st.columns(3)
with left_column:
st.subheader("Total Sales:")
st.subheader(f"US $ {total_sales:,}")
with middle_column:
st.subheader("Average Rating:")
st.subheader(f"{average_rating} {star_rating}")
with right_column:
st.subheader("Average Sales Per Transaction:")
st.subheader(f"US $ {average_sale_by_transaction}")
st.markdown("""---""")

Charts
Both charts follow the same pattern: groupby() sums the sales, and Plotly Express draws a bar chart from the result. The first one shows sales by product line as horizontal bars.
# SALES BY PRODUCT LINE [BAR CHART]
sales_by_product_line = df_selection.groupby(by=["Product line"])[["Total"]].sum().sort_values(by="Total")
fig_product_sales = px.bar(
sales_by_product_line,
x="Total",
y=sales_by_product_line.index,
orientation="h",
title="<b>Sales by Product Line</b>",
color_discrete_sequence=["#0083B8"] * len(sales_by_product_line),
template="plotly_white",
)
fig_product_sales.update_layout(
plot_bgcolor="rgba(0,0,0,0)",
xaxis=(dict(showgrid=False))
)
st.plotly_chart(fig_product_sales)

The second chart shows sales by hour, using the hour column from the cached function. The last three lines place both charts side by side, so the st.plotly_chart(fig_product_sales) line from the first chart is no longer needed.
# SALES BY HOUR [BAR CHART]
sales_by_hour = df_selection.groupby(by=["hour"])[["Total"]].sum()
fig_hourly_sales = px.bar(
sales_by_hour,
x=sales_by_hour.index,
y="Total",
title="<b>Sales by hour</b>",
color_discrete_sequence=["#0083B8"] * len(sales_by_hour),
template="plotly_white",
)
fig_hourly_sales.update_layout(
xaxis=dict(tickmode="linear"),
plot_bgcolor="rgba(0,0,0,0)",
yaxis=(dict(showgrid=False)),
)
left_column, right_column = st.columns(2)
left_column.plotly_chart(fig_hourly_sales, use_container_width=True)
right_column.plotly_chart(fig_product_sales, use_container_width=True)
Streamlit 1.67 still runs use_container_width=True but prints a deprecation notice; the new spelling is width=”stretch”. The transparent background and the hidden grid lines are the same quick fixes for default Plotly Express charts I reach for on every project.
Styling
Two small additions make the app look finished: a CSS block that hides the Streamlit menu, header and footer, and a theme file that sets the colors.
# ---- HIDE STREAMLIT STYLE ----
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
What still applies in current versions is in hiding the Streamlit menu, header and footer. The theme goes into .streamlit/config.toml next to the script:
# .streamlit/config.toml
[theme]
# Primary accent color for interactive elements.
primaryColor = "#E694FF"
# Background color for the main content area.
backgroundColor = "#00172B"
# Background color used for the sidebar and most interactive widgets.
secondaryBackgroundColor = "#0083B8"
# Color used for almost all text.
textColor = "#FFF"
# Font family for all text in the app, except code blocks. One of "sans serif", "serif", or "monospace".
# Default: "sans serif"
font = "sans serif"
To put the dashboard online, follow my guide to deploying a Streamlit app to Render. If you would rather not code the dashboard at all, my free dashboard maker turns pasted Excel data into a shareable dashboard.
