Add symbol markers to columns

master
Dan Howe 5 years ago
parent 0e16048d2e
commit a4e1f3c7a5

@ -7,15 +7,22 @@ import dash_html_components as html
import pandas as pd import pandas as pd
import numpy as np import numpy as np
csv_name = os.path.dirname(__file__) + '../statistics.csv' csv_name = os.path.dirname(__file__) + '../statistics.csv'
df = pd.read_csv(csv_name) df = pd.read_csv(csv_name)
# Round floats # Round floats
df.iloc[:, 1:] = np.round(df.iloc[:, 1:] * 100) / 100 df.iloc[:, 1:] = np.round(df.iloc[:, 1:] * 100) / 100
var_list = ['H_sig', 'H_1%', 'H_max', 'Hm0', 'Tp', 'Tp1'] variables = {
df = df[['location'] + var_list] '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 # 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 # 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['id'] = df.index
# df.set_index('id', inplace=True, drop=False) # df.set_index('id', inplace=True, drop=False)
app = dash.Dash(__name__) app = dash.Dash(__name__)
app.layout = html.Div([ app.layout = html.Div([
dash_table.DataTable( dash_table.DataTable(
id='datatable-row-ids', id='datatable-row-ids',
columns=[ columns=[{
{'name': col, 'id': col} for col in df.columns 'name': [val, key],
# omit the id column 'id': key
if col != 'id' } for key, val in variables.items()],
],
data=df.to_dict('records'), data=df.to_dict('records'),
editable=True, editable=True,
filter_action="native", filter_action="native",
@ -49,11 +54,11 @@ app.layout = html.Div([
]) ])
@app.callback( @app.callback(Output('datatable-row-ids-container', 'children'), [
Output('datatable-row-ids-container', 'children'), Input('datatable-row-ids', 'derived_virtual_row_ids'),
[Input('datatable-row-ids', 'derived_virtual_row_ids'), Input('datatable-row-ids', 'selected_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): def update_graphs(row_ids, selected_row_ids, active_cell):
# When the table is first rendered, `derived_virtual_data` and # When the table is first rendered, `derived_virtual_data` and
# `derived_virtual_selected_rows` will be `None`. This is due to an # `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 active_row_id = active_cell['row_id'] if active_cell else None
colors = ['#FF69B4' if id == active_row_id colors = [
else '#7FDBFF' if id in selected_id_set '#FF69B4' if id == active_row_id else
else '#0074D9' '#7FDBFF' if id in selected_id_set else '#0074D9' for id in row_ids
for id in row_ids] ]
return [ return [
dcc.Graph( dcc.Graph(
id=column + '--row-ids', id=column + '--row-ids',
figure={ figure={
'data': [ 'data': [{
{ 'x': dff['id'],
'x': dff['id'], 'y': dff[column],
'y': dff[column], 'type': 'bar',
'type': 'bar', 'marker': {
'marker': {'color': colors}, 'color': colors
} },
], }],
'layout': { 'layout': {
'xaxis': {'automargin': True}, 'xaxis': {
'automargin': True
},
'yaxis': { 'yaxis': {
'automargin': True, 'automargin': True,
'title': {'text': column} 'title': {
'text': column
}
}, },
'height': 250, '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__': if __name__ == '__main__':
app.run_server(debug=True) app.run_server(debug=False)

Loading…
Cancel
Save