Thank you for your reply @jinnyzor. I have tried with match but I keep getting an error that says
Multiple objects were found for an Output
of a callback that only takes one value. The id spec is {“index”:{“wild”:“MATCH”},“type”:“carouselSes01”} with MATCH values [1] and the property is items
. The objects we found are: [{“id”:{“index”:1,“type”:“carouselSes01”},“property”:“items”},{“id”:{“index”:1,“type”:“carouselSes01”},“property”:“items”}]
I am sure I have not understood well how to use it.
The following is a very simplified code that you can use to help me understand what you have in mind. The pngs for the carousels are found here: https://byu.box.com/s/ut1gk4wiqtasugbzj7hpycp4lh117z3j
# DASH
from dash import html, dcc
from dash.dependencies import Input, Output, State, ALL, MATCH
import dash_bootstrap_components as dbc
from jupyter_dash import JupyterDash
JupyterDash.infer_jupyter_proxy_config()
button_group_ses01= html.Div([dbc.RadioItems(options=[
{"label": "Run-01", "value": 1},
{"label": "Run-03", "value": 2}
],
id= "button_group_ses01",
value = 1,
className="btn-group text-center"
)])
button_group_ses02= html.Div([dbc.RadioItems(options=[
{"label": "Run-01", "value": 1},
{"label": "Run-03", "value": 2}
],
id= "button_group_ses02",
value = 1,
className="btn-group text-center"
)])
ses01 = "assets/QA_cs/sub-DZ17BH/ses-01"
ses02 = "assets/QA_cs/sub-DZ17BH/ses-02"
car01_4_session_01 = dbc.Carousel(
items=[
{"src": f"{ses01}/run-01/fv_snaps_surf_annot_dispind_pial_1_lat_lh.png"},
{"src": f"{ses01}/run-01/fv_snaps_surf_annot_dispind_pial_2_med_lh.png"},
{"src": f"{ses01}/run-01/fv_snaps_surf_annot_dispind_pial_3_inf_lh.png"}
],
id= {"type":f"carouselSes01", "index": 1},
indicators=False,
interval=None,
slide="off",
className="carousel-fade",
)
car02_4_session_01 = dbc.Carousel(
items=[
{"src": f"{ses01}/run-01/fv_snaps_surf_blnk_dispind_pial_1_lat_lh.png"},
{"src": f"{ses01}/run-01/fv_snaps_surf_blnk_dispind_pial_2_med_lh.png"},
{"src": f"{ses01}/run-01/fv_snaps_surf_blnk_dispind_pial_3_inf_lh.png"}
],
id= {"type":f"carouselSes01", "index": 2},
indicators=False,
interval=None,
slide="off",
className="carousel-fade",
)
car01_4_session_02 = dbc.Carousel(
items=[
{"src": f"{ses02}/run-01/fv_snaps_surf_annot_dispind_pial_1_lat_lh.png"},
{"src": f"{ses02}/run-01/fv_snaps_surf_annot_dispind_pial_2_med_lh.png"},
{"src": f"{ses02}/run-01/fv_snaps_surf_annot_dispind_pial_3_inf_lh.png"}
],
id= {"type":f"carouselSes02", "index": 1},
indicators=False,
interval=None,
slide="off",
className="carousel-fade",
)
car02_4_session_02 = dbc.Carousel(
items=[
{"src": f"{ses02}/run-01/fv_snaps_surf_blnk_dispind_pial_1_lat_lh.png"},
{"src": f"{ses02}/fv_snaps_surf_blnk_dispind_pial_2_med_lh.png"},
{"src": f"{ses02}/fv_snaps_surf_blnk_dispind_pial_3_inf_lh.png"}
],
id= {"type":f"carouselSes02", "index": 2},
indicators=False,
interval=None,
slide="off",
className="carousel-fade",
)
app = JupyterDash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = dbc.Container([
dbc.Row([
dbc.Col([
html.H1("SESSION 01"),
button_group_ses01
], width = 4)]),
dbc.Row([
dbc.Col([
car01_4_session_01,
]),
dbc.Col([
car02_4_session_01,
]),
]),
dbc.Row([
dbc.Col([
html.H1("SESSION 02"),
button_group_ses02
], width = 4)]),
dbc.Row([
dbc.Col([
car01_4_session_02,
]),
dbc.Col([
car02_4_session_02,
]),
])
])
# SLIDERS
@app.callback(
Output({"type":"carouselSes01", "index": ALL}, "items"),
Input("button_group_ses01", "value"),
prevent_initial_call=True
)
def update_subjectdata(run_chosen):
runList = ["run-01", "run-03"]
run = runList[run_chosen - 1]
car1=[
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_dispind_pial_1.0_3.5_1_lat_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_dispind_pial_1.0_3.5_2_med_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_dispind_pial_1.0_3.5_3_inf_rh.png"}]
car2=[
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_disptmpl_inflated_1.0_3.5_1_lat_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_disptmpl_inflated_1.0_3.5_med_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_disptmpl_inflated_1.0_3.5_3_inf_rh.png"}]
return [car1,car2]
@app.callback(
Output({"type":"carouselSes02", "index": ALL}, "items"),
Input("button_group_ses02", "value"),
prevent_initial_call=True
)
def update_subjectdata(run_chosen):
runList = ["run-01", "run-03"]
run = runList[run_chosen - 1]
car1=[
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_dispind_pial_1.0_3.5_1_lat_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_dispind_pial_1.0_3.5_2_med_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_dispind_pial_1.0_3.5_3_inf_rh.png"}]
car2=[
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_disptmpl_inflated_1.0_3.5_1_lat_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_disptmpl_inflated_1.0_3.5_med_rh.png"},
{"src": f"{ses01}/{run}/fv_snaps_surf_thickness_disptmpl_inflated_1.0_3.5_3_inf_rh.png"}]
return [car1,car2]
app.run_server(mode ="external", debug=True)
The goal is to be able to update the items property of one set of carrousels using the respective radio buttons and one callback only.
I highly appreciate your insights.