# check out https://dash.plotly.com/ for documentation
# And check out https://py.cafe/maartenbreddels for more examples
from dash import Dash, Input, Output, callback, dcc, html
import pandas as pd
# Load your data
file_path = "World_open_funds_total_net_assets.xlsx"
df = pd.read_excel(file_path, sheet_name='Sheet1', engine = 'openpyxl')
# Create a Dash app
app = Dash(__name__)
# Create a layout for the app
app.layout = html.Div([
html.H1("Net Asset Value by Region"),
# Dropdown for year selection
dcc.Dropdown(
id='year-dropdown',
options=[{'label': str(year), 'value': year} for year in df['Year'].unique()],
value=df['Year'].min(), # Set the default value to the first year
clearable=False
),
# Metric cards to display total net asset value by region
html.Div(id='metric-cards', style={'display': 'flex', 'justify-content': 'space-around', 'margin-top': '20px'})
])
# Define callback to update the metric cards based on selected year
@app.callback(
Output('metric-cards', 'children'),
Input('year-dropdown', 'value')
)
def update_metrics(selected_year):
filtered_data = df[df['Year'] == selected_year]
region_totals = filtered_data.groupby('Region')['Net Asset Value'].sum()
# Create metric cards for each region
metric_cards = []
for region, total_value in region_totals.items():
metric_cards.append(
html.Div([
html.H3(region),
html.H4(f"{total_value:,.0f} Million USD")
], style={'border': '1px solid #ccc', 'padding': '10px', 'border-radius': '5px', 'text-align': 'center'})
)
return metric_cards
# Run the app
if __name__ == '__main__':
app.run_server(debug=True)