I am using BooleanSwitch in my Application. My application has multi-tabs and pages. Here’s the structure for more clarity -
app.py
index.py
- pages
--- home.py
- tabs
--- tab1.py
--- tab2.py
In home.py, I have the following code:
daq.BooleanSwitch(
id="boolean-flow",
on=True, # True = Flow1 and False = Flow2
#label="Label",
labelPosition="bottom"
),
# Update Label of Boolean Switch
@application.callback(
Output('boolean-flow','label'),
[
Input('dummy_div','children'),
Input('boolean-flow','on')
]
)
def update_switchLabel(dummy, on):
if on == True:
return "Flow1"
else:
return "Flow2"
This toggle value is saved in store
element that is defined in index.py
.
# Store component for home page
dcc.Store(id="home-store", storage_type="local"),
In tab1.py, I update certain elements based on the toggle value that’s read from the store
component.
@application.callback([
Output("layout", "style")
],
[
Input("dummy-div", "value"),
],
[
State("home-store", "data")
]
)
def flow_update(dummy, home_store):
print("component from home page", home_store)
if home_store == "Flow1":
return [{"display":"none"}]
elif home_store == "Flow2":
return [{"display":"inline-block"}]
When I toggle the selection, the value of home_store
is not updated for some reason. Could someone review and suggest why that’s the case? home_store
takes the default value and doesn’t update upon toggle. Another way to put this, is how do I check for updates to home_store
and trigger a callback.
I am also checking the dash.callback_context
to for objects triggered including inputs and states. But, not seeing any updates to home_store
state.