forked from vagabond-systems/quantium-starter-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisual_data.py
78 lines (57 loc) · 2.33 KB
/
visual_data.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
import pandas as pd
dtfl = pd.read_csv('managed_data.csv')
dtfl['date'] = pd.to_datetime(dtfl['date'])
app = dash.Dash(__name__)
regions = dtfl['region'].unique()
region_options = [{'label': region, 'value': region} for region in regions]
region_options.append({'label': 'all', 'value': 'All'})
app.layout = html.Div([
html.Div([
html.H1('Select Region', style={'textAlign': 'center', 'color': '#fff', 'font-family': 'Arial', 'margin-bottom': '20px'}),
dcc.RadioItems(
id='radio-buttons',
options=region_options,
value=regions[0],
labelStyle={'display': 'inline-block', 'font-family': 'Arial', 'font-size': '16px', 'margin': '10px', 'cursor': 'pointer', 'color': 'grey'},
),
html.P(id='comparison-results', style={'color': '#ddd', 'font-family': 'Arial', 'fontSize': '18px', 'textAlign': 'center', 'margin-top': '20px'}),
],style={'padding': '20px', 'border': '1px solid #333', 'border-radius': '5px', 'background-color': '#222'}),
html.Div([
dcc.Graph(id='line-chart'),
]),
], style={'margin': '20px', 'font-family': 'Arial', 'background-color': '#000', 'border-radius': '10px'})
@app.callback(
[Output('line-chart', 'figure'),
Output('comparison-results', 'children')],
[Input('radio-buttons', 'value')]
)
def update_chart(sltd_rgn):
if sltd_rgn == 'All':
filtered_dtfl = dtfl
sltd_rgn_label = 'All Regions'
else:
filtered_dtfl = dtfl[dtfl['region'] == sltd_rgn]
sltd_rgn_label = sltd_rgn
figure = {
'data': [
{'x': filtered_dtfl['date'], 'y': filtered_dtfl['sales'], 'type': 'line', 'name': 'Sales'},
],
'layout': {
'title': f'Sales in {sltd_rgn_label}',
'xaxis': {'title': 'Date'},
'yaxis': {'title': 'Sales'},
}
}
sales_after_jan_15 = filtered_dtfl[filtered_dtfl['date'] > '2021-01-15']
sales_increased = sales_after_jan_15['sales'].diff().gt(0).any()
if sales_increased:
cmprn_rslt = "Sales showed improvement after January 15, 2021"
else:
cmprn_rslt = "Sales declined after January 15, 2021."
return figure, cmprn_rslt
if __name__ == '__main__':
app.run_server(debug=True)