i want to create a excel visualising dashboard which gives some KPIS and graphs
To upload files, please first save the app
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime, timedelta
# Set page config
st.set_page_config(page_title="Excel Dashboard", layout="wide")
# Generate sample data
@st.cache_data
def generate_sample_data():
np.random.seed(42)
dates = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D')
data = {
'Date': dates,
'Sales': np.random.uniform(1000, 5000, len(dates)),
'Customers': np.random.randint(50, 200, len(dates)),
'Orders': np.random.randint(100, 400, len(dates)),
'Region': np.random.choice(['North', 'South', 'East', 'West'], len(dates))
}
df = pd.DataFrame(data)
return df
df = generate_sample_data()
# Header
st.title("📊 Business Analytics Dashboard")
st.markdown("---")
# KPI Metrics
col1, col2, col3, col4 = st.columns(4)
with col1:
total_sales = df['Sales'].sum()
st.metric("Total Sales", f"${total_sales:,.2f}")
with col2:
total_customers = df['Customers'].sum()
st.metric("Total Customers", f"{total_customers:,}")
with col3:
total_orders = df['Orders'].sum()
st.metric("Total Orders", f"{total_orders:,}")
with col4:
avg_order_value = total_sales / total_orders
st.metric("Avg Order Value", f"${avg_order_value:.2f}")
st.markdown("---")
# Charts
col1, col2 = st.columns(2)
with col1:
# Sales Trend
sales_trend = px.line(df, x='Date', y='Sales',
title='Daily Sales Trend',
labels={'Sales': 'Sales ($)', 'Date': 'Date'})
st.plotly_chart(sales_trend, use_container_width=True)
# Customer Distribution by Region
region_dist = px.pie(df, names='Region',
values='Customers',
title='Customer Distribution by Region')
st.plotly_chart(region_dist, use_container_width=True)
with col2:
# Orders vs Customers Scatter
scatter = px.scatter(df, x='Customers', y='Orders',
title='Orders vs Customers Correlation',
trendline="ols")
st.plotly_chart(scatter, use_container_width=True)
# Monthly Sales Box Plot
df['Month'] = df['Date'].dt.strftime('%B')
monthly_box = px.box(df, x='Month', y='Sales',
title='Monthly Sales Distribution',
labels={'Sales': 'Sales ($)'})
st.plotly_chart(monthly_box, use_container_width=True)
# Data Table
st.markdown("---")
st.subheader("Raw Data")
st.dataframe(df, use_container_width=True)
# Download Button
csv = df.to_csv(index=False).encode('utf-8')
st.download_button(
label="Download Data as CSV",
data=csv,
file_name="dashboard_data.csv",
mime="text/csv",
)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?