Shantala commited on
Commit
d176754
·
verified ·
1 Parent(s): c9b9e42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -20
app.py CHANGED
@@ -1,27 +1,78 @@
1
- from dash import Dash, Input, Output, callback, dcc, html
 
2
  import dash_bootstrap_components as dbc
 
 
 
3
 
4
- app = Dash(__name__)
5
- app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
 
6
 
7
- md = """
8
- # Dash demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- See [The dash examples index](https://dash-example-index.herokuapp.com/) for more examples.
11
- """
12
-
13
- app.layout = html.Div(
14
- children=[
15
- dcc.Markdown(children=md, link_target="_blank"),
16
- dcc.Dropdown(id="dropdown", options=["red", "green", "blue", "orange"]),
17
- dcc.Markdown(id="markdown", children=["## Hello World"]),
18
- ]
19
  )
 
 
 
 
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- @callback(
23
- Output("markdown", "style"),
24
- Input("dropdown", "value"),
25
- )
26
- def update_markdown_style(color):
27
- return {"color": color}
 
1
+ import dash
2
+ from dash import dcc, html, Input, Output
3
  import dash_bootstrap_components as dbc
4
+ import plotly.express as px
5
+ import pandas as pd
6
+ from ETF_sector_data_prep import sector_df, countries
7
 
8
+ # Initialize the Dash app with Bootstrap theme
9
+ app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
10
+ app.title = "MSCI ETF Sector Weights"
11
 
12
+ # Layout of the app
13
+ app.layout = dbc.Container([
14
+ dbc.Row([
15
+ dbc.Col(html.H1("MSCI ETF Sector Weights", className="text-center"), width=12)
16
+ ]),
17
+ dbc.Row([
18
+ dbc.Col(
19
+ dcc.Dropdown(
20
+ id='country-dropdown',
21
+ options=[{'label': country, 'value': country} for country in countries],
22
+ value=['Singapore'],
23
+ multi=True,
24
+ placeholder="Select Country"
25
+ ),
26
+ width=4
27
+ )
28
+ ], className="mb-4"),
29
+ dbc.Row([
30
+ dbc.Col(
31
+ html.Div("Source: Yahoo! Finance", className="text-end"),
32
+ width=12
33
+ )
34
+ ]),
35
+ dbc.Row([
36
+ dbc.Col(
37
+ dcc.Graph(id='sector-bar-plot', style={"height": "800px"}),
38
+ width=12
39
+ )
40
+ ])
41
+ ], fluid=True)
42
 
43
+ # Callback for updating the plot
44
+ @app.callback(
45
+ Output('sector-bar-plot', 'figure'),
46
+ Input('country-dropdown', 'value')
 
 
 
 
 
47
  )
48
+ def update_sector_plot(selected_countries):
49
+ if not selected_countries:
50
+ filtered_df = pd.DataFrame(columns=sector_df.columns)
51
+ else:
52
+ filtered_df = sector_df[sector_df['Country'].isin(selected_countries)]
53
 
54
+ fig = px.bar(
55
+ filtered_df,
56
+ x="Weight(%)",
57
+ y="Sector_Name",
58
+ color="Country",
59
+ hover_data=['Country', 'Sector_Name', 'Weight(%)'],
60
+ color_discrete_map={
61
+ "Japan": "red",
62
+ "Taiwan": "#00CC96",
63
+ "South Korea": "blue",
64
+ "Hong Kong": "#FBE426",
65
+ "Singapore": "magenta",
66
+ "Australia": "brown",
67
+ "Malaysia": "green",
68
+ "Thailand": "darkblue"
69
+ },
70
+ template="ggplot2",
71
+ barmode='group'
72
+ )
73
+ fig.update_layout(height=800)
74
+ return fig
75
 
76
+ # Run the app
77
+ if __name__ == '__main__':
78
+ app.run_server(debug=True)