I have the following components:
session_picker_row = dbc.Row(
[
dbc.Col(
dcc.Dropdown(
options=list(range(CURRENT_SEASON, 2017, -1)),
placeholder="Select a season",
value=None,
id="season",
)
),
dbc.Col(
dcc.Dropdown(
options=[],
placeholder="Select a event",
value=None,
id="event",
),
),
dbc.Col(
dcc.Dropdown(
options=[],
placeholder="Select a session",
value=None,
id="session",
),
),
dbc.Col(
dcc.Dropdown(
options=[
{"label": "Finishing order", "value": False},
{"label": "Teammate side-by-side", "value": True},
],
value=False,
clearable=False,
id="teammate-comp",
)
),
dbc.Col(
dbc.Button(
children="Load Session / Reorder Drivers",
n_clicks=0,
disabled=True,
color="success",
id="load-session",
)
),
],
)
They are linked by some callbacks:
@callback(
Output("event", "options"),
Output("event", "value"),
Output("event-schedule", "data"),
Input("season", "value"),
prevent_initial_call=True,
)
def set_event_options(
season: int | None,
) -> tuple[list[str], None, dict]:
"""Get the names of all events in the selected season."""
if season is None:
return [], None, None
schedule = f.get_event_schedule(season, include_testing=False)
if season == CURRENT_SEASON:
# only include events for which we have processed data
last_round = DF_DICT[CURRENT_SEASON]["R"]["RoundNumber"].max()
schedule = schedule[schedule["RoundNumber"] <= last_round]
return (
list(schedule["EventName"]),
None,
schedule.set_index("EventName").to_dict(orient="index"),
)
@callback(
Output("session", "options"),
Output("session", "value"),
Input("event", "value"),
State("event-schedule", "data"),
prevent_initial_call=True,
)
def set_session_options(event: str | None, schedule: dict) -> tuple[list[dict], None]:
"""
Return the sessions contained in an event.
Event schedule is passed in as a dictionary with the event names as keys. The values map
column labels to the corresponding entry.
"""
if event is None:
return [], None
return [
{"label": "Race", "value": "R"},
{
"label": "Sprint",
"value": "S",
"disabled": schedule[event]["EventFormat"] not in SPRINT_FORMATS,
},
], None
@callback(
Output("session-debug", "children"),
Input("load-session", "n_clicks"),
)
def session_debug(n_clicks):
return n_clicks
@callback(
Output("load-session", "disabled"),
Input("season", "value"),
Input("event", "value"),
Input("session", "value"),
prevent_initial_call=True,
)
def enable_load_session(season: int | None, event: str | None, session: str | None) -> bool:
"""Toggles load session button on when the previous three fields are filled."""
return not (season is not None and event is not None and session is not None)
In my other issue, I had noted that some pandas code occasionally cause the button’s n_clicks
property to revert to a previous state. When this happens, I also observe session
’s value
property reverting to the previous state. I have checked the callbacks graph to make sure these changes are not results of callbacks.
Might this have something to do with the browser cache? How can I investigate further?