-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04 dash_сallbacks.py
62 lines (53 loc) · 1.75 KB
/
04 dash_сallbacks.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
57
58
59
60
61
62
from dash import Dash, dcc, html, Input, Output, State
import dash_daq as daq
import plotly.express as px
import plotly.graph_objects as go
import okama as ok
app = Dash(__name__)
app.layout = html.Div(
children=[
html.H1('Сравнение активов'),
dcc.Dropdown(
options=['SPY.US', 'BND.US', 'GLD.US', 'VNQ.US', 'MCFTR.INDX'],
multi=True,
placeholder='Выберите ценные бумаги',
id='assets',
value='SPY.US'
),
html.Button(id="button", n_clicks=0, children="Отобразить график"),
dcc.Graph(
id='wealth_indexes'
),
daq.BooleanSwitch(
id='logarithmic-switch',
on=False,
label='Логарифмическая шкала',
labelPosition='bottom'
)
]
)
@app.callback(
Output('wealth_indexes', 'figure'),
Input('logarithmic-switch', 'on'),
Input('button', 'n_clicks'),
State('assets', 'value')
)
def update_graf(on, n_clicks, value: list):
symbols = value if isinstance(value, list) else [value]
df = ok.AssetList(symbols, ccy='USD', inflation=True).wealth_indexes
index = df.index.to_timestamp('M')
fig = px.line(df, x=index, y=df.columns[:-1], log_y=on, height=800)
fig.add_trace(
go.Scatter(
x=index,
y=df.iloc[:, -1],
mode='none',
fill='tozeroy',
fillcolor='rgba(26,150,65,0.5)',
name='Inflation'
)
)
fig.update_xaxes(title='Date', rangeslider_visible=True)
fig.update_yaxes(title=None)
return fig
app.run_server(debug=True)