I have the following callback that runs when a button is clicked
@callback(
Output("laps", "data"),
Input("load-session", "n_clicks"),
State("season", "value"),
State("event", "value"),
State("session", "value"),
prevent_initial_call=True,
)
def get_session_laps(
_: int, # ignores actual_value of n_clicks
season: int,
event: str,
session: str,
) -> dict:
"""
Save the laps of the selected session into browser cache.
Can assume that season, event, and session are all set (not None).
"""
included_laps = DF_DICT[season][session]
included_laps = included_laps[included_laps["EventName"] == event]
included_laps = included_laps.drop(columns=["Time", "PitOutTime", "PitInTime"])
return included_laps.to_dict()
The n_clicks
property start at 0. The first time the button is clicked and this callback is fired, the n_clicks
go up to 1 before returning to 0. I have isolated that the line dropping some columns from the dataframe is causing this behavior.
This is totally unexpected. Where should I look to investigate further?
Relevant section of the layout:
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",
)
),
],
)
The button’s disabled
property is toggled by another callback.