Circular Dependencies error is there a workable solution

I need some input how to solve this problem, please.

I have a checkbox.
I don’t want that all boxes are empty.
If all are uncheked I want one box to be automatically checked on (and maybe inactivated until other box has been checked).
If any other box is checked, 'default box (‘BBB’ in example) can be unchecked.

Here is a code I’m playing with. Code seems to work but I keep getting Circular Dependencies error, and can’t figure out the solution.

Here is a code.

 import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
from jupyter_dash import JupyterDash


app = JupyterDash(__name__)

app.layout = html.Div([
                        html.Div([
                                    dcc.Store(id="aggregate_checkbox_data"),

                                    dcc.Checklist(  id='checklist_1',
                                                    options=[{'label': x, 'value': x*3, 'disabled':False} for x in ['A', 'B', 'C']],
                                                    value=['BBB'], 
                                                    style={'color':'yellow'}),
                            
                                    html.Div(id='display_temp',style={'color':'red'}),      
                                 ]),
                      ])


# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

## C1
@app.callback([ 
                Output('aggregate_checkbox_data', 'data'),
#                 Output('display_temp', 'children')
                ],
                [Input(component_id='checklist_1', component_property='value')],
              )
def eliminate_empty_values(checklist_values):
    if len(checklist_values) == 0:
        checklist_values = ['BBB']
    return checklist_values, # checklist_values


## C2
@app.callback([
                Output('display_temp', 'children'),
                Output(component_id='checklist_1', component_property='value')
              ],
              [Input('aggregate_checkbox_data', 'data')],
             )
def funk(checklist_values):
    return checklist_values, checklist_values





app.run_server(mode='jupyterlab', port = 8090, dev_tools_ui=True, #debug=True,
          dev_tools_hot_reload =True, threaded=True) 

Hi @Marcas,
You could try returning a new checkbox as part of the callback triggered by the checkboxes’ value update. That way if the value is empty, you return default checkboxes (where only “B” is active). See the code below for an example:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State

app = dash.Dash(__name__)

default_value=["BBB"]

default_checklist = dcc.Checklist(
    id="checklist_1",
    options=[
        {"label": x, "value": x * 3, "disabled": False} for x in ["A", "B", "C"]
    ],
    value=default_value,
    style={"color": "yellow"},
)

app.layout = html.Div(children=[
    html.Div(id="result-shower"),
    html.Div(
        id="checklistwrap",
        children=[
            default_checklist
        ]
    )
])

@app.callback(
[Output("checklistwrap","children"),Output("result-shower","children")],
Input("checklist_1","value"),
State("checklistwrap","children"))
def show_checked(check1_value,checkwrap):
    if check1_value == []:
        return (default_checklist," ".join(default_value))
    return (checkwrap, " ".join(check1_value))

if __name__ == "__main__":
    app.run_server()

Hope this helps :slight_smile:

It does help. Thank you @nickest.