I am trying to understand how callbacks work. From the online documentation, this code illustrates how to population a dropdown:
from dash import Dash, dcc, html, Input, Output,callback
app = Dash(name)
app.layout = html.Div([
dcc.Dropdown([‘NYC’, ‘MTL’, ‘SF’], ‘NYC’, id=‘demo-dropdown’),
html.Div(id=‘dd-output-container’)
])@callback(
Output(‘dd-output-container’, ‘children’),
Input(‘demo-dropdown’, ‘value’)
)
def update_output(value):
return f’You have selected {value}’
I don’t understand how the callback statement relates to the update_output function. It looks like the selected value from the demo-dropdown becomes an input to the update_output function, but how is the returned result (the “You have selected…” string), but how is the update_output function linked to the “Output” in the callback? Is it dependent on the name of the function?
I want to use the callback to update a second dropdown, but I don’t see how to use the callback structure to do this. I’d appreciate any explanation about how this works.
TIA