In my dash app I can pass the **kwargs to layout components like dropdown in a following manner:
def dropdown1(**kwargs):
return dbc.Col(
dcc.Dropdown(
id='dropdown1',
options=options_dropdown(),
value=kwargs.get("value1"),
) )
All the following dropdowns in my app are dependent on chosen value in the first dropdown. The callback(s) for those dropdowns would always override their respective kwargs in the layout.
I tried to pass **kwargs to callback like:
@callback(
Output("dropdown2", "options"),
Output("dropdown2", "value"),
Input("dropdown1", "value"),
prevent_initial_call=False
)
def update_dropdown2 (dropdown1_value, **kwargs):
if not dropdown1_value:
return [], []
dropdown2_kwarg = kwargs.get('value2')
if dropdown2_kwarg is not None:
dropdown2_kwarg = dropdown2_kwarg [0]
dropdown2_opts = get_dropdown2_opts(dropdown1_value)
all_values = [option['value'] for option in dropdown2_opts]
if dropdown2_kwarg is not None:
return All_strenght_opts, [dropdown2_kwarg]
return dropdown2_opts, all_values
This does not work either. Also, with Input(‘_pages_location’, ‘path’), I get
Property “path” was used with component ID: “_pages_location” in one of the Input items of a callback. This ID is assigned to a dash_core_components.Location component in the layout, which does not support this property.
Also tried
@callback(
Output("dropdown2", "options"),
Output("dropdown2", "value"),
Input("dropdown1", "value"),
Input('_pages_location', 'pathname'),
prevent_initial_call=True
)
def update_dropdown2 (dropdown1_value, path):
parsed_url = urlparse(path)
query_params = parse_qs(parsed_url.query)
Dropdown2_kwarg = query_params.get('phase')
but the returned kwarg is None eventhough it’s present in URL