I was unaware of the ctx attribute, but when I added this in, it runs perfectly. Does that mean it’s a bug or I just wasn’t using the correct attribute?
Noted on the MRE. I will do so next time. The answer in context for later users (copy and paste works):
import dash_mantine_components as dmc
from dash import Dash, _dash_renderer, Input, Output, ctx
_dash_renderer._set_react_version("18.2.0")
import random
app = Dash(external_stylesheets=dmc.styles.ALL)
# # # # # # # # # lyt
comp0 = dmc.Card(
[
dmc.Button(
"PLAY",
color="rgb(8,81,156)",
size="xl",
radius="xl",
id="comp7_SELECTclick_playbutton"
)
],
className="t s7",
)
comp1 = dmc.Paper(
[
dmc.Text(
[
],
id="PAP_ms10_2",
className="t ms10_0 nv e"
),
dmc.Text(
[
dmc.Text(
"-",
size="xl",
className=" nv_m e"
)
],
className="t ms10_1 nv e"
),
dmc.Text(
[
],
id="PAP_ms10_3",
className="t ms10_2 nv e"
),
],
withBorder=True,
radius="md",
className="t ms10",
)
comp2 = dmc.Card(
[
dmc.SegmentedControl(
data=["HOME", "AWAY"],
value="HOME",
id="comp5p0_SELECTclick_homeoraway"
),
dmc.Text(
[
],
id="PAP_s5_1",
)
],
className="t s5"
)
lyt = dmc.MantineProvider([
comp0,
comp1,
comp2
])
# # # # # # # # # # # callback
@app.callback(
Output("PAP_ms10_2", "children"),
Output("PAP_ms10_3", "children"),
Output("PAP_s5_1", "children"),
Input("comp7_SELECTclick_playbutton", "n_clicks"),
Input("comp5p0_SELECTclick_homeoraway", "value"),
)
def nice(nclicks, homeoraway_switch):
if nclicks is None:
return "0", "0", ""
else:
if ctx.triggered_id== "comp7_SELECTclick_playbutton":
print(nclicks)
home_score = random.choice(range(0, 30))
away_score = random.choice(range(0, 30))
if home_score > away_score:
if homeoraway_switch == "HOME":
return dmc.Text(f"{home_score}"), dmc.Text(f"{away_score}"), dmc.Text("You win!(0)")
elif homeoraway_switch == "AWAY":
return dmc.Text(f"{home_score}"), dmc.Text(f"{away_score}"), dmc.Text("You lose(1)!")
elif home_score < away_score:
if homeoraway_switch == "HOME":
return dmc.Text(f"{home_score}"), dmc.Text(f"{away_score}"), dmc.Text("You lose(2)!")
elif homeoraway_switch == "AWAY":
return dmc.Text(f"{home_score}"), dmc.Text(f"{away_score}"), dmc.Text("You win(3)!")
elif home_score == away_score:
return dmc.Text(f"{home_score}", c="gray", className="nv e"), dmc.Text(f"{away_score}", c="gray", className="nv e"), dmc.Text("One point. (4)")
elif ctx.triggered_id == "comp5p0_SELECTclick_homeoraway":
return "0", "0", ""
# # # # # # # # # # # # run
app.layout = lyt
if __name__ == "__main__":
app.run(debug=True, port=9999)
Thank you for your help, you are a lifesaver!