-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
169 lines (134 loc) · 4.3 KB
/
app.py
File metadata and controls
169 lines (134 loc) · 4.3 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import dash
import dash_html_components as html
import dash_core_components as dcc
import analysis
from dash.dependencies import Input, Output
df = analysis.import_data()
app = dash.Dash('drug-discovery')
server = app.server
external_css = ["https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css",
"//fonts.googleapis.com/css?family=Raleway:400,300,600",
"//fonts.googleapis.com/css?family=Dosis:Medium"]
for css in external_css:
app.css.append_css({"external_url": css})
BACKGROUND = 'rgb(252, 252, 252)'
def scatter_plot_3d(
x=df[0]['X'],
y=df[0]['Y'],
z=df[0]['Phase'],
color=df[0]['Color'],
xlabel='X',
ylabel='Y',
zlabel='Phase',
plot_type='scatter3d', ):
def axis_template_3d(title, type='linear'):
return dict(
showbackground=True,
backgroundcolor=BACKGROUND,
gridcolor='rgb(225, 225, 225)',
title=title,
type=type,
zerolinecolor='rgb(252, 252, 252)'
)
def axis_template_2d(title):
return dict(
xgap = 10, ygap = 10,
backgroundcolor = BACKGROUND,
gridcolor = 'rgb(100, 100, 100)',
dtick = 2,
title = title,
zerolinecolor = 'rgb(0, 0, 0)',
color = '#444'
)
data = [dict(
x=x,
y=y,
z=z,
mode='markers',
marker=dict(
line=dict(color='#444'),
reversescale=True,
sizeref=45,
sizemode='diameter',
opacity=0.7,
color=color,
),
text=df[0]['Name'],
type=plot_type,
)]
layout = dict(
font=dict(family='Raleway'),
hovermode='closest',
showlegend=False,
scene=dict(
xaxis=axis_template_3d(xlabel),
yaxis=axis_template_3d(ylabel),
zaxis=axis_template_3d(zlabel),
camera=dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=0.1, y=0.1, z=2.5)
)
)
)
if plot_type == 'scatter':
layout['xaxis'] = axis_template_2d(xlabel)
layout['yaxis'] = axis_template_2d(ylabel)
layout['plot_bgcolor'] = BACKGROUND
layout['paper_bgcolor'] = BACKGROUND
del layout['scene']
del data[0]['z']
# if trial != '1':
# layout['xaxis'] = axis_template_2d(xlabel)
# layout['yaxis'] = axis_template_2d(ylabel)
# layout['plot_bgcolor'] = BACKGROUND
# layout['paper_bgcolor'] = BACKGROUND
# del layout['scene']
# del data[0]['z']
return dict(data=data, layout=layout)
FIGURE = scatter_plot_3d()
app.layout = html.Div([
# Main body
html.Div([
html.Div([
html.Div([
html.P(
'Click and drag to rotate the graph in 3D, scroll to zoom.'),
], style={'text-align': 'center'}),
], className='jumbotron'),
], className='container'),
# Graph
html.Div([
html.Div([
# dcc.Dropdown(
# id='trial-input',
# options=[{'label': str(i+1), 'value': str(i+1)}
# for i in range(8)],
# value='1',
# multi=False
# ),
dcc.RadioItems(
id = 'charts_radio',
options=[
dict( label='3D Scatter', value='scatter3d' ),
dict( label='2D Scatter', value='scatter' ),
],
labelStyle = dict(display='inline'),
value='scatter3d'
),
dcc.Graph(id='clickable-graph',
style=dict(height='1250px',width='1400px'),
hoverData=dict( points=[dict(pointNumber=0)] ),
figure=FIGURE ),
], className='nine columns', style=dict(textAlign='center')),
], className='row', style={'margin-left': '25%'}),
])
@app.callback(
Output('clickable-graph', 'figure'),
[Input('charts_radio', 'value'),
#Input('trial-input', 'value')
])
def highlight_molecule(plot_type):
return scatter_plot_3d(plot_type=plot_type)
if __name__ == '__main__':
app.run_server()