Py.Cafe

sh.mukherjee+py/

dash-net-asset-value-by-region

Net Asset Value by Region

DocsPricing
  • World_open_funds_total_net_assets.xlsx
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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)