Hi. Running databricks_dash on Databricks, when I run an app containing a callback it produces a duplicate callback error if I rerun the app.run cell.
Example code:
def create_fig(dataitem):
df = pd.DataFrame({'col1': [1,2,3,4,5],
'col2': [6,7,8,9,10]
})
df = df[df['col1'] > dataitem]
fig = go.Figure()
fig.add_trace(go.Scatter(x=df['col1'],
y=df['col2']))
return fig
radioit = html.Div(dcc.RadioItems(options=[1,2,3,4,5], value=5, id='radio'))
app = DatabricksDash(__name__, external_stylesheets=[dbc.themes.MINTY])
app.layout = dbc.Container(
[
html.H1("Test chart"),
html.Br(),
dbc.Row(dbc.Col(radioit),),
html.Br(),
dbc.Row(dbc.Col(dcc.Graph(id='line-chart'))),
], fluid=True
)
@callback(
Output(component_id='line-chart', component_property='figure'),
Input(component_id='radio', component_property='value'),
)
def append_own_data(
dataitem,
):
return create_fig(dataitem)
app.run(debug=True)
When I run this cell for the first time it renders the app correctly, but if I rerun the cell in databricks I get the error duplicate callback.
Error message:
⛑️
Duplicate callback outputs
15:32:57
In the callback for output(s):
line-chart.figure
Output 0 (line-chart.figure) is already in use.
To resolve this, set `allow_duplicate=True` on
duplicate outputs, or combine the outputs into
one callback function, distinguishing the trigger
by using `dash.callback_context` if necessary.