Design a modern DRE spreadsheet with a minimalist style. Use bold headers and distinct sections for Revenue, Costs, Operating Expenses and Net Income. Apply a refined blue-gray palette with subtle gradients, integrated charts and ample white space to ensure clear, dynamic data presentation. Exceed.
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Set page config for a cleaner look
st.set_page_config(layout="wide", page_title="DRE Dashboard")
# Custom CSS for styling
st.markdown("""
<style>
.main {
background-color: #f8f9fa;
}
.stMetric {
background-color: white;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.section-header {
color: #2c3e50;
font-weight: 600;
font-size: 1.2rem;
margin-bottom: 1rem;
}
</style>
""", unsafe_allow_html=True)
# Sample data
def generate_sample_data():
data = {
'Revenue': {
'Product Sales': 850000,
'Service Revenue': 450000,
'Other Income': 75000
},
'Costs': {
'Cost of Goods Sold': 425000,
'Direct Labor': 275000,
'Materials': 150000
},
'Operating_Expenses': {
'Salaries': 225000,
'Marketing': 95000,
'Rent': 85000,
'Utilities': 45000,
'Insurance': 35000
}
}
return data
# Initialize session state for editable values
if 'data' not in st.session_state:
st.session_state.data = generate_sample_data()
# Title
st.title('Dynamic Revenue & Expense Dashboard')
st.markdown('---')
# Main content
col1, col2 = st.columns([2, 1])
with col1:
# Revenue Section
st.markdown('<p class="section-header">📈 REVENUE</p>', unsafe_allow_html=True)
revenue_data = st.session_state.data['Revenue']
revenue_df = pd.DataFrame(revenue_data.items(), columns=['Item', 'Amount'])
total_revenue = sum(revenue_data.values())
# Create an editable revenue table
for index, (item, amount) in enumerate(revenue_data.items()):
new_value = st.number_input(
f"{item}",
value=float(amount),
key=f"revenue_{index}",
format="%,.0f"
)
st.session_state.data['Revenue'][item] = new_value
st.markdown('---')
# Costs Section
st.markdown('<p class="section-header">💰 COSTS</p>', unsafe_allow_html=True)
costs_data = st.session_state.data['Costs']
for index, (item, amount) in enumerate(costs_data.items()):
new_value = st.number_input(
f"{item}",
value=float(amount),
key=f"costs_{index}",
format="%,.0f"
)
st.session_state.data['Costs'][item] = new_value
st.markdown('---')
# Operating Expenses Section
st.markdown('<p class="section-header">📊 OPERATING EXPENSES</p>', unsafe_allow_html=True)
opex_data = st.session_state.data['Operating_Expenses']
for index, (item, amount) in enumerate(opex_data.items()):
new_value = st.number_input(
f"{item}",
value=float(amount),
key=f"opex_{index}",
format="%,.0f"
)
st.session_state.data['Operating_Expenses'][item] = new_value
with col2:
# Calculate totals
total_revenue = sum(st.session_state.data['Revenue'].values())
total_costs = sum(st.session_state.data['Costs'].values())
total_opex = sum(st.session_state.data['Operating_Expenses'].values())
net_income = total_revenue - total_costs - total_opex
# Display metrics
st.metric("Total Revenue", f"${total_revenue:,.0f}")
st.metric("Total Costs", f"${total_costs:,.0f}")
st.metric("Total Operating Expenses", f"${total_opex:,.0f}")
st.metric("Net Income", f"${net_income:,.0f}",
delta=f"{(net_income/total_revenue)*100:.1f}% of Revenue")
# Create waterfall chart
fig = go.Figure(go.Waterfall(
name="DRE", orientation="v",
measure=["relative", "relative", "relative", "total"],
x=["Revenue", "Costs", "Operating Expenses", "Net Income"],
text=[f"${val:,.0f}" for val in [total_revenue, -total_costs, -total_opex, net_income]],
y=[total_revenue, -total_costs, -total_opex, 0],
connector={"line": {"color": "rgb(63, 63, 63)"}},
decreasing={"marker": {"color": "#EF553B"}},
increasing={"marker": {"color": "#00B5F7"}},
totals={"marker": {"color": "#2c3e50"}}
))
fig.update_layout(
title="Financial Waterfall",
showlegend=False,
plot_bgcolor='white',
height=400,
margin=dict(t=50, l=0, r=0, b=0)
)
st.plotly_chart(fig, use_container_width=True)
# Create pie charts for breakdown
fig = make_subplots(rows=1, cols=3, specs=[[{'type':'domain'}, {'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=list(st.session_state.data['Revenue'].keys()),
values=list(st.session_state.data['Revenue'].values()),
name="Revenue"), 1, 1)
fig.add_trace(go.Pie(labels=list(st.session_state.data['Costs'].keys()),
values=list(st.session_state.data['Costs'].values()),
name="Costs"), 1, 2)
fig.add_trace(go.Pie(labels=list(st.session_state.data['Operating_Expenses'].keys()),
values=list(st.session_state.data['Operating_Expenses'].values()),
name="Operating Expenses"), 1, 3)
fig.update_layout(
height=300,
title_text="Breakdown Analysis",
annotations=[
dict(text='Revenue', x=0.11, y=0.5, font_size=12, showarrow=False),
dict(text='Costs', x=0.50, y=0.5, font_size=12, showarrow=False),
dict(text='Operating Expenses', x=0.89, y=0.5, font_size=12, showarrow=False)
]
)
st.plotly_chart(fig, use_container_width=True)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?