diff --git a/daqviewer/tables.py b/daqviewer/tables.py index a952ba9..fc0fa10 100644 --- a/daqviewer/tables.py +++ b/daqviewer/tables.py @@ -5,15 +5,25 @@ import dash_table import dash_core_components as dcc 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, index_col=0).T +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] + # 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 # renamed 'country' to 'id' (but given it the display name 'country'), but # here it's duplicated just to show the more general pattern. df['id'] = df.index -# df.set_index('location', inplace=True, drop=False) +# df.set_index('id', inplace=True, drop=False) + app = dash.Dash(__name__) @@ -21,7 +31,7 @@ app.layout = html.Div([ dash_table.DataTable( id='datatable-row-ids', columns=[ - {'name': i, 'id': i} for i in df.columns + {'name': i, 'id': i, 'deletable': True} for i in df.columns # omit the id column if i != 'id' ], @@ -78,7 +88,7 @@ def update_graphs(row_ids, selected_row_ids, active_cell): figure={ 'data': [ { - 'x': dff.index, + 'x': dff['id'], 'y': dff[column], 'type': 'bar', 'marker': {'color': colors}, @@ -98,7 +108,7 @@ def update_graphs(row_ids, selected_row_ids, active_cell): # check if column exists - user may have deleted it # If `column.deletable=False`, then you don't # need to do this check. - for column in dff.columns + for column in ['pop', 'lifeExp', 'gdpPercap'] if column in dff ]