I have created a demo app.
I have 3 buttons and dcc link connected to those and a dropdown menu.
I want if I am clicking any of those button which is redirecting to href, I want to maintain the states of other components except the one which is being directly updated.
for the below code.
since dropdown callback is getting triggered by the btn-1 style property, this will trigger at the start of the page
but when I am clicking on the button my url is changing without refreshing the page but the problem is my dropdown callback is getting triggered again.
can i maintain it state? is it possible?
thanks in advance
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash import html, dcc, dash
import dash
from dash.dependencies import Input, Output, State
dash.register_page(__name__, path="/test")
layout = html.Div([
html.Div([], id="test"),
dcc.Link(html.Button(["Click 1"], id="btn-1"), href=dash.get_relative_path("/test/?n=1")),
dcc.Link(html.Button(["Click 2"], id="btn-2"), href=dash.get_relative_path("/test/?n=2")),
dcc.Link(html.Button(["Click 3"], id="btn-3"), href=dash.get_relative_path("/test/?n=3")),
dcc.Dropdown(id="test-dd")
])
@dash.callback(
Output("test-dd", "options"),
Input("btn-1", "style")
)
def dd_update(style):
print(f'udpate dd')
return ["a", "b", "c"]
@dash.callback(
[Output("test", "children")],
[Input('btn-1', "n_clicks"),
Input('btn-2', "n_clicks"),
Input('btn-3', "n_clicks"),]
)
def udpate(n_clicks_1, n_clicks_2, n_clicks_3):
print(n_clicks_1, n_clicks_2, n_clicks_3)
if n_clicks_1:
return ["click 1"]
if n_clicks_2:
return ["click 2"]
if n_clicks_3:
return ["click 3"]
return [],