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_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
import numpy as np
@ -80,56 +81,24 @@ def update_graphs(row_ids, selected_row_ids, active_cell):
# the component.
selected_id_set = set(selected_row_ids or [])
if row_ids is None:
dff = df
# pandas Series works enough like a list for this to be OK
row_ids = df['id']
if selected_id_set:
dff = df.loc[selected_id_set]
else:
dff = df.loc[row_ids]
active_row_id = active_cell['row_id'] if active_cell else None
colors = [
'#FF69B4' if i == active_row_id else
'#7FDBFF' if i in selected_id_set else '#0074D9' for i in row_ids
]
return [
dcc.Graph(
id=column + '--row-ids',
figure={
'data': [{
'x': dff['id'],
'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
]
dff = df
spec = []
for i, row in dff.iterrows():
x = np.arange(10)
y = x * row['H_sig']
trace = go.Scatter(x=x, y=y, name=i)
spec.append(trace)
energy = dict(data=spec)
graph = dcc.Graph(id='time-series', figure=energy)
return graph
if __name__ == '__main__':

Loading…
Cancel
Save