Only plot selected rows

master
Dan Howe 5 years ago
parent f36f4f2d2c
commit ba1a53a9a3

@ -4,6 +4,7 @@ from dash.dependencies import Input, Output
import dash_table 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 plotly.graph_objs as go
import pandas as pd import pandas as pd
import numpy as np import numpy as np
@ -80,56 +81,24 @@ def update_graphs(row_ids, selected_row_ids, active_cell):
# the component. # the component.
selected_id_set = set(selected_row_ids or []) selected_id_set = set(selected_row_ids or [])
if row_ids is None: if selected_id_set:
dff = df dff = df.loc[selected_id_set]
# pandas Series works enough like a list for this to be OK
row_ids = df['id']
else: else:
dff = df.loc[row_ids] dff = df
active_row_id = active_cell['row_id'] if active_cell else None spec = []
for i, row in dff.iterrows():
colors = [ x = np.arange(10)
'#FF69B4' if i == active_row_id else y = x * row['H_sig']
'#7FDBFF' if i in selected_id_set else '#0074D9' for i in row_ids
] trace = go.Scatter(x=x, y=y, name=i)
spec.append(trace)
return [
dcc.Graph( energy = dict(data=spec)
id=column + '--row-ids',
figure={ graph = dcc.Graph(id='time-series', figure=energy)
'data': [{
'x': dff['id'], return graph
'y': dff[column],
'type': 'bar',
'marker': {
'color': colors
},
}],
'layout': {
'xaxis': {
'automargin': True
},
'yaxis': {
'automargin': True,
'title': {
'text': column
}
},
'height': 250,
'margin': {
't': 10,
'l': 10,
'r': 10
},
},
},
)
# 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 ['H_sig', 'H_1%', 'H_max'] if column in dff
]
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save