Make table rows undeletable

master
Dan Howe 5 years ago
parent dcc6968a30
commit 67e4ed0e88

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

Loading…
Cancel
Save