Product_Performance_Dashboard / src /streamlit_app.py
deepakpathania's picture
Update src/streamlit_app.py
019bb97 verified
Raw
History Blame Contribute Delete
5.22 kB
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Set page to wide mode
st.set_page_config(layout="wide", page_title="Product Performance Dashboard")
# --- CUSTOM CSS FOR THE EXACT LOOK ---
st.markdown("""
<style>
/* Dark Header */
.header-container {
background-color: #0e1e2c;
padding: 1.5rem;
border-radius: 0px 0px 10px 10px;
color: white;
margin-bottom: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
/* Metric Cards */
div[data-testid="stMetric"] {
background-color: white;
border: 1px solid #f0f2f6;
padding: 15px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
/* Chart Containers */
.chart-container {
background-color: white;
padding: 20px;
border-radius: 10px;
border: 1px solid #e6e9ef;
}
</style>
""", unsafe_allow_index=True)
# --- LOAD DATA ---
@st.cache_data
def load_data():
df = pd.read_csv('weekly_synthetic_product_performance_dashboard.xlsx - Weekly Product Dashboard Data.csv')
df['Week Start Date'] = pd.to_datetime(df['Week Start Date'])
# Using 'Simulation Performance' as a proxy for units to match image visuals
df['Units Sold'] = (df['Simulation Performance'] * 15).astype(int)
return df
df = load_data()
# --- HEADER ---
st.markdown("""
<div class="header-container">
<div>
<h1 style='margin:0; font-size:24px;'>QUANTUMLEAP DYNAMICS</h1>
<p style='margin:0; opacity:0.8;'>WEEKLY PRODUCT PERFORMANCE DASHBOARD</p>
</div>
<div style='text-align:right;'>
<small>JD | QuantumLeap Dynamics Inc.</small>
</div>
</div>
""", unsafe_allow_index=True)
# --- TOP FILTERS ---
weeks = sorted(df['Week Start Date'].unique(), reverse=True)
col_filter = st.columns([2, 10])
with col_filter[0]:
selected_week = st.selectbox("", weeks, format_func=lambda x: x.strftime('%d %b - %d %b'))
# Filtering data for metrics
current_data = df[df['Week Start Date'] == selected_week]
avg_revenue = df['Revenue (USD)'].mean()
avg_rating = df['Product Performance Score'].mean()
# --- ROW 1: METRICS ---
m1, m2, m3, m4, m5, m6 = st.columns(6)
with m1:
st.metric("TOTAL REVENUE", f"${current_data['Revenue (USD)'].sum()/1e6:.2f}M", "+18.2%")
with m2:
st.metric("SELECTED WEEK", f"${current_data['Revenue (USD)'].sum()/1e6:.2f}M", "+0.2% vs AVG")
with m3:
st.metric("TOTAL SALES VOLUME", f"{current_data['Units Sold'].sum()/1000:.1f}K", "+1.4%")
with m4:
st.metric("UNITS SOLD", f"{int(current_data['Units Sold'].sum()):,}", "+0.3% vs AVG")
with m5:
st.metric("CUSTOMER SATISFACTION", f"{current_data['Satisfaction Score'].mean() + 5:.2f}/5", "+2.8%")
with m6:
st.metric("AVG RATING", f"{current_data['Product Performance Score'].mean():.1f}", "+2.8% vs AVG")
st.markdown("<br>", unsafe_allow_index=True)
# --- ROW 2: TOP PRODUCTS ---
top_4 = current_data.nlargest(4, 'Revenue (USD)')
p_cols = st.columns(4)
for i, (idx, row) in enumerate(top_4.iterrows()):
with p_cols[i]:
st.markdown(f"""
<div style="border: 1px solid #e6e9ef; padding: 10px; border-radius: 8px;">
<b style="font-size: 14px;">{row['Customer Name']}</b><br>
<span style="color: #666;">${row['Revenue (USD)']/1000:.0f}K | {row['Units Sold']} Units</span>
</div>
""", unsafe_allow_index=True)
# --- ROW 3: PIE & SCATTER ---
st.markdown("<br>", unsafe_allow_index=True)
c1, c2 = st.columns(2)
with c1:
st.subheader("Product Contribution - Sales Volume")
fig_pie = px.pie(current_data, values='Units Sold', names='Customer Name', hole=0.5,
color_discrete_sequence=px.colors.qualitative.Prism)
fig_pie.update_layout(margin=dict(t=0, b=0, l=0, r=0), showlegend=True)
st.plotly_chart(fig_pie, use_container_width=True)
with c2:
st.subheader("Revenue vs. Sales Volume")
fig_scatter = px.scatter(current_data, x='Units Sold', y='Revenue (USD)',
text='Customer Name', size='Revenue (USD)',
color='Customer Name')
fig_scatter.update_traces(textposition='top center')
st.plotly_chart(fig_scatter, use_container_width=True)
# --- ROW 4: TRENDS ---
st.markdown("<br>", unsafe_allow_index=True)
t1, t2, t3 = st.columns(3)
# Aggregate for trends
trend_df = df.groupby('Week Start Date').mean().reset_index()
with t1:
st.caption("Unit Price Trend")
fig1 = px.area(trend_df, x='Week Start Date', y='Revenue (USD)', color_discrete_sequence=['#4e7054'])
st.plotly_chart(fig1, use_container_width=True)
with t2:
st.caption("Customer Satisfaction Trend")
fig2 = px.area(trend_df, x='Week Start Date', y='Satisfaction Score', color_discrete_sequence=['#8e5194'])
st.plotly_chart(fig2, use_container_width=True)
with t3:
st.caption("Average Rating Trend")
fig3 = px.line(trend_df, x='Week Start Date', y='Product Performance Score', color_discrete_sequence=['#77b38d'])
st.plotly_chart(fig3, use_container_width=True)