Commit ·
76b0ae2
1
Parent(s): d190235
Fix Arrow.width error: replace width='stretch' with use_container_width=True and add try/except error handling for charts
Browse files
app.py
CHANGED
|
@@ -286,67 +286,83 @@ else:
|
|
| 286 |
|
| 287 |
# Render Clean DataFrame
|
| 288 |
st.markdown("### 📈 Optimal Allocation Data Profile Table")
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
# Graphical Visualizations in Columns
|
| 301 |
chart_col1, chart_col2 = st.columns(2)
|
| 302 |
|
| 303 |
with chart_col1:
|
| 304 |
st.markdown("### 📊 Optimal Spend Allocation per Platform")
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
go.
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
| 315 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
)
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
height=400,
|
| 324 |
-
hovermode="x unified"
|
| 325 |
-
)
|
| 326 |
-
st.plotly_chart(fig_bar, width="stretch")
|
| 327 |
|
| 328 |
with chart_col2:
|
| 329 |
st.markdown("### 🍕 Percentage Budget Distribution")
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
go.
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
)
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
)
|
| 349 |
-
st.plotly_chart(fig_pie, width="stretch")
|
| 350 |
|
| 351 |
with tab2:
|
| 352 |
# Technical Solver summary logs for reviews
|
|
|
|
| 286 |
|
| 287 |
# Render Clean DataFrame
|
| 288 |
st.markdown("### 📈 Optimal Allocation Data Profile Table")
|
| 289 |
+
try:
|
| 290 |
+
st.dataframe(
|
| 291 |
+
df_profile.style.format({
|
| 292 |
+
"Optimal Budget Allocation (₹)": "₹{:,.2f}",
|
| 293 |
+
"Budget Share (%)": "{:.2f}%",
|
| 294 |
+
"Reach Efficiency (Views/₹)": "{:,.1f}",
|
| 295 |
+
"Expected Impressions (Views)": "{:,.0f}"
|
| 296 |
+
}),
|
| 297 |
+
use_container_width=True,
|
| 298 |
+
hide_index=True
|
| 299 |
+
)
|
| 300 |
+
except Exception as chart_err:
|
| 301 |
+
st.warning(f"⚠️ Table rendering issue: {chart_err}")
|
| 302 |
+
st.write(df_profile)
|
| 303 |
|
| 304 |
# Graphical Visualizations in Columns
|
| 305 |
chart_col1, chart_col2 = st.columns(2)
|
| 306 |
|
| 307 |
with chart_col1:
|
| 308 |
st.markdown("### 📊 Optimal Spend Allocation per Platform")
|
| 309 |
+
try:
|
| 310 |
+
# Plotly Corporate Styled Bar Chart
|
| 311 |
+
fig_bar = go.Figure(data=[
|
| 312 |
+
go.Bar(
|
| 313 |
+
x=platform_names,
|
| 314 |
+
y=spend_splits,
|
| 315 |
+
text=[f"₹{s:,.0f}" for s in spend_splits],
|
| 316 |
+
textposition='auto',
|
| 317 |
+
marker=dict(
|
| 318 |
+
color=['#6c5ce7', '#0984e3', '#00cec9'],
|
| 319 |
+
line=dict(color='rgba(0, 0, 0, 0.1)', width=1)
|
| 320 |
+
)
|
| 321 |
)
|
| 322 |
+
])
|
| 323 |
+
fig_bar.update_layout(
|
| 324 |
+
yaxis_title="Budget Split (₹)",
|
| 325 |
+
xaxis_title="Platform",
|
| 326 |
+
template="plotly_white",
|
| 327 |
+
margin=dict(l=20, r=20, t=20, b=20),
|
| 328 |
+
height=400,
|
| 329 |
+
hovermode="x unified"
|
| 330 |
)
|
| 331 |
+
st.plotly_chart(fig_bar, use_container_width=True)
|
| 332 |
+
except Exception as chart_err:
|
| 333 |
+
st.warning(f"⚠️ Bar chart rendering failed: {chart_err}")
|
| 334 |
+
st.write("**Optimal Spend Allocation:**")
|
| 335 |
+
for name, spend in zip(platform_names, spend_splits):
|
| 336 |
+
st.write(f"- {name}: ₹{spend:,.2f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
|
| 338 |
with chart_col2:
|
| 339 |
st.markdown("### 🍕 Percentage Budget Distribution")
|
| 340 |
+
try:
|
| 341 |
+
# Plotly Corporate Styled Pie Chart
|
| 342 |
+
fig_pie = go.Figure(data=[
|
| 343 |
+
go.Pie(
|
| 344 |
+
labels=platform_names,
|
| 345 |
+
values=spend_splits,
|
| 346 |
+
hole=0.4,
|
| 347 |
+
marker=dict(
|
| 348 |
+
colors=['#6c5ce7', '#0984e3', '#00cec9']
|
| 349 |
+
),
|
| 350 |
+
textinfo='percent+label',
|
| 351 |
+
insidetextorientation='radial'
|
| 352 |
+
)
|
| 353 |
+
])
|
| 354 |
+
fig_pie.update_layout(
|
| 355 |
+
template="plotly_white",
|
| 356 |
+
margin=dict(l=20, r=20, t=20, b=20),
|
| 357 |
+
height=400,
|
| 358 |
+
showlegend=False
|
| 359 |
)
|
| 360 |
+
st.plotly_chart(fig_pie, use_container_width=True)
|
| 361 |
+
except Exception as chart_err:
|
| 362 |
+
st.warning(f"⚠️ Pie chart rendering failed: {chart_err}")
|
| 363 |
+
st.write("**Budget Distribution:**")
|
| 364 |
+
for name, spend, pct in zip(platform_names, spend_splits, percentages):
|
| 365 |
+
st.write(f"- {name}: ₹{spend:,.2f} ({pct:.1f}%)")
|
|
|
|
|
|
|
| 366 |
|
| 367 |
with tab2:
|
| 368 |
# Technical Solver summary logs for reviews
|