Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -147,30 +147,96 @@ def generate_sample_data():
|
|
| 147 |
|
| 148 |
# --- Page Rendering Functions ---
|
| 149 |
def render_dashboard():
|
| 150 |
-
st.header("π Performance Dashboard")
|
|
|
|
|
|
|
| 151 |
data = generate_sample_data()
|
|
|
|
| 152 |
|
|
|
|
| 153 |
col1, col2, col3, col4 = st.columns(4)
|
| 154 |
with col1:
|
| 155 |
-
st.metric("Total Revenue",
|
|
|
|
|
|
|
| 156 |
with col2:
|
| 157 |
-
st.metric("Total Users",
|
|
|
|
|
|
|
| 158 |
with col3:
|
| 159 |
-
st.metric("Avg Engagement",
|
|
|
|
|
|
|
| 160 |
with col4:
|
| 161 |
-
st.metric("
|
|
|
|
|
|
|
| 162 |
|
|
|
|
| 163 |
col1, col2 = st.columns(2)
|
|
|
|
| 164 |
with col1:
|
| 165 |
-
st.subheader("Revenue
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
with col2:
|
| 170 |
-
st.subheader("User Engagement
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
def render_analytics():
|
| 176 |
st.header("π Data Analytics")
|
|
|
|
| 147 |
|
| 148 |
# --- Page Rendering Functions ---
|
| 149 |
def render_dashboard():
|
| 150 |
+
st.header("π Comprehensive Business Performance Dashboard")
|
| 151 |
+
|
| 152 |
+
# Generate sample data with more complex structure
|
| 153 |
data = generate_sample_data()
|
| 154 |
+
data['Profit_Margin'] = data['Revenue'] * np.random.uniform(0.1, 0.3, len(data))
|
| 155 |
|
| 156 |
+
# Top-level KPI Section
|
| 157 |
col1, col2, col3, col4 = st.columns(4)
|
| 158 |
with col1:
|
| 159 |
+
st.metric("Total Revenue",
|
| 160 |
+
f"${data['Revenue'].sum():,.2f}",
|
| 161 |
+
delta=f"{data['Revenue'].pct_change().mean()*100:.2f}%")
|
| 162 |
with col2:
|
| 163 |
+
st.metric("Total Users",
|
| 164 |
+
f"{data['Users'].sum():,}",
|
| 165 |
+
delta=f"{data['Users'].pct_change().mean()*100:.2f}%")
|
| 166 |
with col3:
|
| 167 |
+
st.metric("Avg Engagement",
|
| 168 |
+
f"{data['Engagement'].mean():.2%}",
|
| 169 |
+
delta=f"{data['Engagement'].pct_change().mean()*100:.2f}%")
|
| 170 |
with col4:
|
| 171 |
+
st.metric("Profit Margin",
|
| 172 |
+
f"{data['Profit_Margin'].mean():.2%}",
|
| 173 |
+
delta=f"{data['Profit_Margin'].pct_change().mean()*100:.2f}%")
|
| 174 |
|
| 175 |
+
# Visualization Grid
|
| 176 |
col1, col2 = st.columns(2)
|
| 177 |
+
|
| 178 |
with col1:
|
| 179 |
+
st.subheader("Revenue & Profit Trends")
|
| 180 |
+
fig_revenue = go.Figure()
|
| 181 |
+
fig_revenue.add_trace(go.Scatter(
|
| 182 |
+
x=data['Date'],
|
| 183 |
+
y=data['Revenue'],
|
| 184 |
+
mode='lines',
|
| 185 |
+
name='Revenue',
|
| 186 |
+
line=dict(color='blue')
|
| 187 |
+
))
|
| 188 |
+
fig_revenue.add_trace(go.Scatter(
|
| 189 |
+
x=data['Date'],
|
| 190 |
+
y=data['Profit_Margin'],
|
| 191 |
+
mode='lines',
|
| 192 |
+
name='Profit Margin',
|
| 193 |
+
line=dict(color='green')
|
| 194 |
+
))
|
| 195 |
+
fig_revenue.update_layout(height=350)
|
| 196 |
+
st.plotly_chart(fig_revenue, use_container_width=True)
|
| 197 |
|
| 198 |
with col2:
|
| 199 |
+
st.subheader("User Engagement Analysis")
|
| 200 |
+
fig_engagement = px.scatter(
|
| 201 |
+
data,
|
| 202 |
+
x='Users',
|
| 203 |
+
y='Engagement',
|
| 204 |
+
color='Category',
|
| 205 |
+
size='Revenue',
|
| 206 |
+
hover_data=['Date'],
|
| 207 |
+
title='User Engagement Dynamics'
|
| 208 |
+
)
|
| 209 |
+
fig_engagement.update_layout(height=350)
|
| 210 |
+
st.plotly_chart(fig_engagement, use_container_width=True)
|
| 211 |
+
|
| 212 |
+
# Category Performance
|
| 213 |
+
st.subheader("Category Performance Breakdown")
|
| 214 |
+
category_performance = data.groupby('Category').agg({
|
| 215 |
+
'Revenue': 'sum',
|
| 216 |
+
'Users': 'sum',
|
| 217 |
+
'Engagement': 'mean'
|
| 218 |
+
}).reset_index()
|
| 219 |
+
|
| 220 |
+
fig_category = px.bar(
|
| 221 |
+
category_performance,
|
| 222 |
+
x='Category',
|
| 223 |
+
y='Revenue',
|
| 224 |
+
color='Engagement',
|
| 225 |
+
title='Revenue by Category with Engagement Overlay'
|
| 226 |
+
)
|
| 227 |
+
st.plotly_chart(fig_category, use_container_width=True)
|
| 228 |
+
|
| 229 |
+
# Bottom Summary
|
| 230 |
+
st.subheader("Quick Insights")
|
| 231 |
+
insights_col1, insights_col2 = st.columns(2)
|
| 232 |
+
|
| 233 |
+
with insights_col1:
|
| 234 |
+
st.metric("Top Performing Category",
|
| 235 |
+
category_performance.loc[category_performance['Revenue'].idxmax(), 'Category'])
|
| 236 |
+
|
| 237 |
+
with insights_col2:
|
| 238 |
+
st.metric("Highest Engagement Category",
|
| 239 |
+
category_performance.loc[category_performance['Engagement'].idxmax(), 'Category'])
|
| 240 |
|
| 241 |
def render_analytics():
|
| 242 |
st.header("π Data Analytics")
|