-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayouts.py
256 lines (241 loc) · 8.03 KB
/
layouts.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# -*- coding: utf-8 -*-
import os.path
import dash
import uuid
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import visdcc
import dash_reusable_components as drc
import dx_tools
from backend import dist_par_template
configs = {}
#default layout of the chart
chart_layout = {
'hovermode':"closest",
#'legend'=dict(x=0, y=-0.01, orientation="h"),
'autosize':True,
'margin':dict(l=0, r=0, t=0, b=0),
#'plot_bgcolor': "white", #"#282b38",
#'paper_bgcolor': "white", #"#282b38",
#'font':{"color": "black"}, #"#a5b1cd"},
'template': 'plotly_white',
'title': {
'text':'Plot Title',
'font': {
#'family': 'Courier New, monospace',
'size': 12
},
'xref': 'paper',
'x': 0.05,
},
#'title_fontsize': 10,
'xaxis': {
'title':'Exceedance Probability',
#'autorange': 'reversed',
'type':'linear',
#'gridcolor':'lightgrey',
'tickcolor':'grey',
'gridcolor':'grey',
'gridwidth':1,
'showgrid':True,
'zeroline':False,
},
'yaxis': {
'showgrid':True,
'zeroline':False,
'tickcolor':'grey',
'gridwidth':1,
'gridcolor':'grey'
}, #'gridcolor':'lightgrey',}
}
graph_config = {
'toImageButtonOptions': {
'format': 'png',
'height': 500*2,
'width': 800*2,
}
}
def server_layout(mode=None):
#return the layout of the GUI
session_id = str(uuid.uuid4())
#variable, distribution selection panel
selection_panel = html.Div(id='selection-panel',children=[
html.Div(id='selected-column-panel',children=[
html.Div(id='selected-column-sec1-panel',children=[
drc.NamedDropdown(
name='Select series',
id='selected-series',
searchable=False,
clearable=False
),
dcc.Checklist(
id='apply-log-transform',
options=[{'label':' Apply log transform','value':'logtransform'}
]),
]),
drc.NamedTextarea(
id='series-characteristics',
name='Series characteristics',
cols='50',
rows='2',
readOnly='readOnly'
),
]),
html.Div(id='apply-panel',children=[
html.Div(id='apply-sec1-panel',children=[
drc.NamedDropdown(
id='fitted-distributions',
name='Fitted distribution',
options=[
{'label': ' '+ v[0], 'value': k}
for k,v in dist_par_template.items() if k != 'native' and v[2]
],
value='normal',
searchable=False,
clearable=False
),
]),
# html.Div(id='apply-sec1b-panel',children=[
# drc.NamedDropdown(
# id='plotting-distributions',
# name='Probability scale',
# options=[
# {'label': ' '+ v[0], 'value': k}
# for k,v in dist_par_template.items() if v[2]
# ],
# value='native',
# searchable=False,
# clearable=False
# ),
# ]),
html.Div(id='apply-sec2a-panel',children=[
html.Button('Fit',id='fit-button',n_clicks=0),
]),
#dcc.Checklist(
# id='show-y-log',
# options=[{'label':' Show y-axis in log scale','value':'true'}
#]),
]),
html.Label(id='graph-refresh'),
dcc.Store(
id='graph-refresh-hidden',
data=0
),
html.Div(id='message-panel',children=[""]),
])
#variable, distribution selection panel
par_panel = html.Div(id='fitted-panel',children=[
html.Div(id='fitted-sec1-panel',children=[
drc.NamedTextarea(
id='fitted-par',
name='Estimated distribution parameters',
readOnly='readOnly',
cols= 40,
rows= 3
),
drc.NamedTextarea(
id='estimated-quantiles',
name='Estimated quantiles',
readOnly='readOnly',
cols= 40,
rows= 3
),
])
])
upload_panel = html.Div(id='last-card',children=[
dcc.Upload(
id='upload-data',
children=html.Div([
'Drag and Drop or ',
html.A('Select File')
]),
style={
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
}
),
html.Label('''File upload limited to < %0.0f Kb, containing no more than %d rows and %d columns'''%(configs['max_file_size']/1024,configs['max_file_rows'],configs['max_file_cols'])),
html.Label('',id='data-filename'),
html.Label('',id='data-description'),
html.Div(id='table-panel',children=[
dash_table.DataTable(
id='attribute-table',
columns=[],
row_selectable='multi',
editable=False,
style_header={
'textAlign': 'center',
'fontWeight': 'bold',
'color': 'black',
},
style_cell={
'padding': '2px',
'--selected-background': 'grey',
'color': 'black',
},
style_data_conditional=[
{
'if': {'row_index': 'odd'},
'backgroundColor': 'rgb(248, 248, 248)'
}
],
#locale_format= '0.3',
)
],style={'visibility':'none','display':'none'}),
])
chart_panel = html.Div(id='chart-panel',children=[
dcc.Loading(id = "loading-icon", children=[
dcc.Graph(
id='graph',
figure={
},
responsive=True,
config=graph_config,
style={'display':'none'}
)
]),
],
style={'visibility':'none'})
layout = html.Div(
id="body",
className="container scalable",
children=[
visdcc.Run_js(id = 'chart-updated-js'),
visdcc.Run_js(id = 'chart-unupdated-js'),
visdcc.Run_js(id = 'error-display-js'),
dcc.Store(id='error-display',data=''),
html.Title(title=configs['title']),
#hidden session id
#row 1 for title
html.Div(id='top-panel',children=[
html.H5(id='app-title',children=
'''Distribution Fitting and Analysis Tool.
This tool is only for demostration porpuses''',
style={"margin-bottom": "0px"},
),
],className="row flex-display"),
#second row layout
html.Div(id='main-panel',children=[
html.Div(id='left-panel',children=[
upload_panel
]),
html.Div(id='output-panel',children=[
selection_panel,
par_panel,
chart_panel
],style={'visibility':'none','display':'none'}),
]),
#row 4 is the footer
html.Div(id='footer-panel',children=[
'''
A web application built on top of Dash (v%s) (framework for Python) by
Exequiel Sepúlveda and Dmitri Kavetski.'''%(dash.__version__)
]),
],
)
return layout