I have created the following code to generate an output based on an dropdown which lies in a tab. However, the code is not working and produces the following error:
Attempting to connect a callback Input item to component: "my-input" but no components with that id exist in the layout.
import dash
from dash import html
from dash import dcc
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
tab1 = html.Div([
html.H3('Tab 1'),
])
tab2 = html.Div([
html.H3('Tab 2'),
dcc.Dropdown(
id='my-input',
options=[
{'label': 'label_first', 'value': 'first'},
{'label': 'label_second', 'value': 'second'},
],
value='first'
),
html.Div(id='my-output'),
])
app.layout = html.Div([
html.H1('Dash Tabs component demo'),
dcc.Tabs(id="tabs", value='1', children=[
dcc.Tab(label='Overview', value='1'),
dcc.Tab(label='Tab Two', value='2'),
]),
html.Div(id='tab-output')
])
@app.callback(
Output('tab-output', 'children'),
Input('tabs', 'value'))
def render_content(tab):
if tab == '1':
return tab1
elif tab == '2':
return tab2
@app.callback(
Output('my-output', 'figure'),
Input('my-input', 'value'))
def update_div(input_value):
return f'Output: {input_value}'
if __name__ == "__main__":
app.run_server(debug=True)