-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
103 lines (90 loc) · 3.06 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
from components import Column, Header, Row
import plotly.graph_objs as go
import plotly.plotly as py
from datetime import datetime as dt
import json
from math import ceil
app = dash.Dash(__name__)
server = app.server
pharmacies = pd.read_csv("data/pharmacies.csv")
prescriptionOfDrugs = pd.read_csv("data/prescriptionofdrugs.csv")
prescriptions = pd.read_csv("data/prescriptions.csv")
# Standard Dash app code below
app.layout = html.Div(className='container', children=[
Header("Pharma421"),
html.Pre(id='selected-data'),
Row(
children = [
html.Div(
className="pretty_container six columns",
children=[
dcc.Graph(
id="leftGraph",
figure={
"data": [
go.Scatter(
x=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
y=[len([True for date in prescriptions["prescription_date"] if (dt.strptime(date, "%Y-%m-%d").month==i)]) for i in range(1, 13)]
)
],
"layout": dict(
title="Monthly Prescription Count",
autosize=True,
margin=dict(
l=45,
r=45,
b=45,
t=55
),
hovermode="closest",
plot_bgcolor="#F9F9F9",
paper_bgcolor="#F9F9F9",
)
}
)
]
),
html.Div(
className="pretty_container six columns",
children=[
dcc.Graph(id="rightGraph")
]
),
]
)
])
@app.callback(
Output("rightGraph", "figure"),
[Input("leftGraph", "relayoutData")])
def updateLeftGraph(relayoutData):
labels = list(set(prescriptions["complaint"]))
data=[
{
"type": "pie",
"labels": labels,
"values": [len(prescriptions[prescriptions["complaint"] == i]) for i in labels],
"hoverinfo": "label+value+percent",
"textinfo": "label+percent+name"
}
]
layout = dict(
title="Complaints Breakdown",
autosize=True,
margin=dict(
l=45,
r=45,
b=45,
t=55
),
hovermode="closest",
plot_bgcolor="#F9F9F9",
paper_bgcolor="#F9F9F9",
)
return dict(data=data, layout=layout)
if __name__ == '__main__':
app.run_server(debug=True)