Shantala commited on
Commit
cfa3b9e
·
verified ·
1 Parent(s): bca125a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -73
app.py CHANGED
@@ -1,78 +1,21 @@
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)
 
1
  import dash
2
+ from dash import dcc, html
 
 
 
 
3
 
4
+ # example for https://community.plotly.com/t/two-graphs-side-by-side/5312
 
 
5
 
6
+ external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ app = dash.Dash(external_stylesheets=external_stylesheets)
9
+ app.layout = html.Div([
10
+ html.Div([
11
+ html.Div([
12
+ html.H3('Column 1'),
13
+ dcc.Graph(id='g1', figure={'data': [{'y': [1, 2, 3]}]})
14
+ ], className="six columns"),
 
 
 
15
 
16
+ html.Div([
17
+ html.H3('Column 2'),
18
+ dcc.Graph(id='g2', figure={'data': [{'y': [1, 2, 3]}]})
19
+ ], className="six columns"),
20
+ ], className="does-not-matter-can-be-container")
21
+ ])