Skip to content

Commit b969c89

Browse files
committed
with mpl
1 parent 34f3998 commit b969c89

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

behavior_data_visualizer/main.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import numpy as np
66
from pathlib import Path
77
from lecilab_behavior_analysis import df_transforms as dft
8+
from lecilab_behavior_analysis import figure_maker as fm
9+
import io
10+
import base64
811

912
# Load the data
1013
outpath = "/mnt/c/Users/HMARTINEZ/LeCiLab/data"
@@ -20,22 +23,34 @@
2023

2124
# Create the layout
2225
app.layout = dash.html.Div([
23-
dash.html.H1("Behavior Data Visualization"),
24-
dash.dcc.Checklist(
25-
id='dropdown',
26-
options=[{'label': key, 'value': key} for key in data_dict.keys()],
27-
value=[list(data_dict.keys())[0]],
28-
labelStyle={'display': 'block'}
29-
),
30-
dash.dcc.Graph(id='graph')
26+
dash.dcc.Tabs([
27+
dash.dcc.Tab(label='Reactive', children=[
28+
dash.dcc.Checklist(
29+
id='checklist',
30+
options=[{'label': key, 'value': key} for key in data_dict.keys()],
31+
value=[list(data_dict.keys())[0]],
32+
labelStyle={'display': 'block'}
33+
),
34+
dash.dcc.Graph(id='graph')
35+
]),
36+
37+
dash.dcc.Tab(label='Reports', children=[
38+
dash.dcc.Dropdown(
39+
id='dropdown',
40+
options=[{'label': key, 'value': key} for key in data_dict.keys()],
41+
value=list(data_dict.keys())[0],
42+
multi=False,
43+
),
44+
dash.html.Img(id='dropdown-graph', src=''),
45+
]),
46+
])
3147
])
3248

3349
# Create the callback
3450
@app.callback(
3551
dash.dependencies.Output('graph', 'figure'),
36-
[dash.dependencies.Input('dropdown', 'value')]
52+
[dash.dependencies.Input('checklist', 'value')],
3753
)
38-
3954
def update_figure(selected_value):
4055
# merge the datasets of the selected mice
4156
tdfs = []
@@ -47,6 +62,22 @@ def update_figure(selected_value):
4762
fig = px.line(tdf, x='total_trial', y='performance_w', color='mouse_name')
4863
return fig
4964

65+
@app.callback(
66+
dash.dependencies.Output('dropdown-graph', component_property='src'),
67+
[dash.dependencies.Input('dropdown', 'value')],
68+
)
69+
def update_dropdown_figure(selected_value):
70+
df = data_dict[selected_value]
71+
fig = fm.subject_progress_figure(df, selected_value)
72+
return fig_to_uri(fig)
73+
74+
def fig_to_uri(fig):
75+
buf = io.BytesIO()
76+
fig.savefig(buf, format='png')
77+
# buf.seek(0)
78+
fig_data = base64.b64encode(buf.getbuffer()).decode("ascii")
79+
return f'data:image/png;base64,{fig_data}'
80+
5081
# Run the app
5182
if __name__ == '__main__':
5283
app.run_server(debug=True)

0 commit comments

Comments
 (0)