Hi, I have a simple scenario using TriggerTransform from dash extensions.
And I want the text field to show a value (current timestamp) only when the value in the 2nd dropdown menu or the checklist is changed. However, the text field is changed also when only changing the options of the 2nd dropdown menu (that are assigned by the 1st dropdown menu value).
Is this a feature, a known bug, or am I missing something?
See the code below :
from dash_extensions.enrich import Output, Input, Trigger
from dash import dcc, html
import dash_bootstrap_components as dbc
from dash_extensions.enrich import DashProxy, TriggerTransform
import time
app = DashProxy(__name__, transforms=[TriggerTransform()])
app.layout = html.Div([
html.Div([
"Dropdown1",
dcc.Dropdown(id="my-dropdown1", options=[{'label': 'a', 'value': 'a'}, {'label': 'b', 'value': 'b'}])
]),
html.Div([
"Dropdown2",
dcc.Dropdown(id="my-dropdown2")
]),
html.Div([
dbc.Checklist(
options=[{"label": "label 1", "value": 0}, {"label": "label 2", "value": 1}],
value=[0],
id="my-checklist",
inline=True
)
]),
html.Div([
"Text field",
html.Div(id="my-text-field")
])
])
@app.callback(
Output('my-dropdown2', 'options'),
Input('my-dropdown1', 'value')
)
def on_1_selected(source):
if source == 'a':
vehicle_list = [1, 2, 3, 4]
else:
vehicle_list = [10, 20, 30, 40]
return [{'label': n, 'value': n} for n in vehicle_list]
@app.callback(
Output('my-text-field', 'children'),
Input('my-dropdown2', 'value'), Trigger('my-checklist', 'value')
)
def on_2_selected(value):
if value is None:
value = time.time()
return value
if __name__ == "__main__":
app.run_server(debug=True)