Skip to content

Commit

Permalink
added callback for updating event dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
niksirbi committed Apr 3, 2023
1 parent 7207edd commit 86199d3
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions wazp/callbacks/events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

import dash
from dash import Input, Output

Expand All @@ -23,17 +21,15 @@ def get_callbacks(app: dash.Dash) -> None:
)
def update_events_video_select(
app_storage: dict,
) -> tuple[list, Optional[str]]:
) -> tuple[list, str]:
"""Update the video selection dropdown with the videos defined in
the project configuration file.
Parameters
----------
app_storage : dict
dictionary with the following keys and values:
- 'config': a dict with the project configuration parameters
- 'metadata_fields': a dict with a set of attributes
- 'video_paths': a dict storing paths to the video files
data held in temporary memory storage,
accessible to all tabs in the app
Returns
-------
Expand All @@ -45,10 +41,49 @@ def update_events_video_select(
Currently selected video name
"""

options = []
if "video_paths" in app_storage:
options = [
{"label": v, "value": v} for v in app_storage["video_paths"]
]
value = options[0]["value"] if options else None
return options, value
value = options[0]["value"]
return options, value
else:
return dash.no_update, dash.no_update

@app.callback(
[
Output("event-select", "options"),
Output("event-select", "value"),
],
Input("session-storage", "data"),
)
def update_event_select_options(
app_storage: dict,
) -> tuple[list, str]:
"""Update the options of the event select dropdown with
the event tags defined in the project configuration file.
Parameters
----------
app_storage : dict
data held in temporary memory storage,
accessible to all tabs in the app
Returns
-------
options : list
list of dictionaries with the following keys and values:
- 'label': event tag
- 'value': event tag
value : str
Currently selected event tag
"""
if "config" in app_storage.keys():
# Get ROI names from stored config
config = app_storage["config"]
event_tags = config["event_tags"]
options = [{"label": t, "value": t} for t in event_tags]
value = event_tags[0]
return options, value
else:
return dash.no_update, dash.no_update

0 comments on commit 86199d3

Please sign in to comment.