Hi,
I define a component inside a callback and use it as Input in the same callback. See a snapshot:
import dash
import dash_html_components as html
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
from dash import ctx, no_update
from plotly.subplots import make_subplots
app = dash.Dash(__name__, suppress_callback_exceptions=True)
tab = html.Div(
children=[
html.Div(
dcc.RadioItems(
id='data_on',
options=[
{'label': 'Raw data', 'value': 'raw_data'},
{'label': 'Filter data', 'value': 'filter_data'},
],
value='raw_data',
style={'display': 'flex', 'width': '50%'},
),
html.Div(id='update_components', children=[]),
),
html.Div(children=[dcc.Graph(id='graph', figure={})]),
]
)
@app.callback(
[
Output('graph', 'figure'),
Output('update_components', 'children')
],
[
Input('data_on', 'value'),
Input('window', 'value')
],
)
def update(option, window):
context = ctx.triggered_id
if context == 'data_on':
if option == 'filter_data':
value = dcc.Input(
id='window',
type='number',
placeholder='window',
value=5,
style={'width': '60px'},
)
# Modify `graph` component as well ....
figure = make_subplots(.....)
....
.....
figure.add_trace(....)
return figure, [value]
if context == 'window':
# Use `window` to modify `graph`
figure = make_subplots(.....)
....
.....
figure.add_trace(....)
return figure, no_update
if __name__ == "__main__":
app.run_server()
app.layout = tab
And I get the error: A nonexistent object was used in an Input
of a Dash callback.
The issue is that I am trying to use as Input a component that has not been defined yet.
Any workaround to overcome this error? Because the kind of visualization, I cannot separate this callback into two.
Best regards,
Manuel