|
|
|
@ -7,15 +7,22 @@ import dash_html_components as html
|
|
|
|
|
import pandas as pd
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
csv_name = os.path.dirname(__file__) + '../statistics.csv'
|
|
|
|
|
df = pd.read_csv(csv_name)
|
|
|
|
|
|
|
|
|
|
# Round floats
|
|
|
|
|
df.iloc[:, 1:] = np.round(df.iloc[:, 1:] * 100) / 100
|
|
|
|
|
|
|
|
|
|
var_list = ['H_sig', 'H_1%', 'H_max', 'Hm0', 'Tp', 'Tp1']
|
|
|
|
|
df = df[['location'] + var_list]
|
|
|
|
|
variables = {
|
|
|
|
|
'H_sig': 'o',
|
|
|
|
|
'H_1%': 'x',
|
|
|
|
|
'H_max': '□',
|
|
|
|
|
'Hm0': '◊',
|
|
|
|
|
'Tp': '',
|
|
|
|
|
'Tp1': '',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
df = df[['location'] + list(variables.keys())]
|
|
|
|
|
|
|
|
|
|
# add an id column and set it as the index
|
|
|
|
|
# in this case the unique ID is just the country name, so we could have just
|
|
|
|
@ -24,17 +31,15 @@ df = df[['location'] + var_list]
|
|
|
|
|
df['id'] = df.index
|
|
|
|
|
# df.set_index('id', inplace=True, drop=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = dash.Dash(__name__)
|
|
|
|
|
|
|
|
|
|
app.layout = html.Div([
|
|
|
|
|
dash_table.DataTable(
|
|
|
|
|
id='datatable-row-ids',
|
|
|
|
|
columns=[
|
|
|
|
|
{'name': col, 'id': col} for col in df.columns
|
|
|
|
|
# omit the id column
|
|
|
|
|
if col != 'id'
|
|
|
|
|
],
|
|
|
|
|
columns=[{
|
|
|
|
|
'name': [val, key],
|
|
|
|
|
'id': key
|
|
|
|
|
} for key, val in variables.items()],
|
|
|
|
|
data=df.to_dict('records'),
|
|
|
|
|
editable=True,
|
|
|
|
|
filter_action="native",
|
|
|
|
@ -49,11 +54,11 @@ app.layout = html.Div([
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.callback(
|
|
|
|
|
Output('datatable-row-ids-container', 'children'),
|
|
|
|
|
[Input('datatable-row-ids', 'derived_virtual_row_ids'),
|
|
|
|
|
@app.callback(Output('datatable-row-ids-container', 'children'), [
|
|
|
|
|
Input('datatable-row-ids', 'derived_virtual_row_ids'),
|
|
|
|
|
Input('datatable-row-ids', 'selected_row_ids'),
|
|
|
|
|
Input('datatable-row-ids', 'active_cell')])
|
|
|
|
|
Input('datatable-row-ids', 'active_cell')
|
|
|
|
|
])
|
|
|
|
|
def update_graphs(row_ids, selected_row_ids, active_cell):
|
|
|
|
|
# When the table is first rendered, `derived_virtual_data` and
|
|
|
|
|
# `derived_virtual_selected_rows` will be `None`. This is due to an
|
|
|
|
@ -75,31 +80,39 @@ def update_graphs(row_ids, selected_row_ids, active_cell):
|
|
|
|
|
|
|
|
|
|
active_row_id = active_cell['row_id'] if active_cell else None
|
|
|
|
|
|
|
|
|
|
colors = ['#FF69B4' if id == active_row_id
|
|
|
|
|
else '#7FDBFF' if id in selected_id_set
|
|
|
|
|
else '#0074D9'
|
|
|
|
|
for id in row_ids]
|
|
|
|
|
colors = [
|
|
|
|
|
'#FF69B4' if id == active_row_id else
|
|
|
|
|
'#7FDBFF' if id in selected_id_set else '#0074D9' for id in row_ids
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
dcc.Graph(
|
|
|
|
|
id=column + '--row-ids',
|
|
|
|
|
figure={
|
|
|
|
|
'data': [
|
|
|
|
|
{
|
|
|
|
|
'data': [{
|
|
|
|
|
'x': dff['id'],
|
|
|
|
|
'y': dff[column],
|
|
|
|
|
'type': 'bar',
|
|
|
|
|
'marker': {'color': colors},
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
'marker': {
|
|
|
|
|
'color': colors
|
|
|
|
|
},
|
|
|
|
|
}],
|
|
|
|
|
'layout': {
|
|
|
|
|
'xaxis': {'automargin': True},
|
|
|
|
|
'xaxis': {
|
|
|
|
|
'automargin': True
|
|
|
|
|
},
|
|
|
|
|
'yaxis': {
|
|
|
|
|
'automargin': True,
|
|
|
|
|
'title': {'text': column}
|
|
|
|
|
'title': {
|
|
|
|
|
'text': column
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'height': 250,
|
|
|
|
|
'margin': {'t': 10, 'l': 10, 'r': 10},
|
|
|
|
|
'margin': {
|
|
|
|
|
't': 10,
|
|
|
|
|
'l': 10,
|
|
|
|
|
'r': 10
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
@ -111,4 +124,4 @@ def update_graphs(row_ids, selected_row_ids, active_cell):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
app.run_server(debug=True)
|
|
|
|
|
app.run_server(debug=False)
|
|
|
|
|