I am trying to run a callback based on a button click but get KeyError: “Callback function not found for output ‘…EEp_msg.children…EEp_table.data…’, perhaps you forgot to prepend the ‘@’?”
What I am trying to do take input from a dropdown, and two input field, upon clicking the ‘ADD’ button, it will make changes in three output components. 1) shows a string message, 2) update the data property of a Dash-table, 3) update a figure.
I could not able to make it works.
Note: I am using Dash proxy app
from dash_extensions.enrich import DashProxy, MultiplexerTransform
app = DashProxy(prevent_initial_callbacks=True, transforms=[MultiplexerTransform()])
server = app.server
Sample error message and code are given below.
Error message:
[2022-07-06 09:08:36,993] ERROR in app: Exception on /_dash-update-component [POST]
Traceback (most recent call last):
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\dash\dash.py”, line 1297, in dispatch
cb = self.callback_map[output]
KeyError: ‘…EEp_msg.children…EEp_table.data…’
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\flask\app.py”, line 2447, in wsgi_app
response = self.full_dispatch_request()
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\flask\app.py”, line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\flask\app.py”, line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\flask_compat.py”, line 39, in reraise
raise value
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\flask\app.py”, line 1950, in full_dispatch_request
rv = self.dispatch_request()
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\flask\app.py”, line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File “C:\Users\tghosh.STUDENT\Anaconda3\lib\site-packages\dash\dash.py”, line 1335, in dispatch
raise KeyError(msg.format(output)) from missing_callback_function
KeyError: “Callback function not found for output ‘…EEp_msg.children…EEp_table.data…’, perhaps you forgot to prepend the ‘@’?”
10.112.43.194 - - [06/Jul/2022 09:08:36] “POST /_dash-update-component HTTP/1.1” 500 –
Callback function:
@app.callback(Output('EEp_msg', 'children'),
Output('EEp_table', 'data'),
Output('FI_plot','children'),
Input('Bt_add_eep','n_clicks'),
State('ddEEdesp','value'),
State('eep_st_time','value'),
State('eep_end_time','value'),
prevent_initial_call=True)
def add_eating_episode(n_clicks,desp,sttime,endtime):
global tfiv
if n_clicks>0:
# print('inside n_click')
arr_hhmmss = sttime.split(':')
sttime2 = selecteddate+3600*int(arr_hhmmss[0])+60*int(arr_hhmmss[1])
arr_hhmmss = endtime.split(':')
endtime2 = selecteddate+3600*int(arr_hhmmss[0])+60*int(arr_hhmmss[1])
msg = procDB.insert_eating_episode(current_pDBInfo,selecteddate,sttime2,endtime2,
'Image-annotation',2,desp,true_eating_episode=1)
data = get_updated_EEpdata()
update_tfiv()
return msg,data,dcc.Graph(figure = createFIplot(),)
Layout:
def getlayout():
update_tfiv()
leftcol = html.Div([
html.Div(id='FI_plot',
children=dcc.Graph(
figure = createFIplot(),
)
),
],style={'padding': 1, 'flex': '70%'})
rightcol = html.Div(children=[
dcc.ConfirmDialog(
id='confirm-delete',
message='Are you sure to delete this?',
),
html.P('Enter Eating Episodes'),
enterEEp,
html.Br(),
html.Button('Add',id='Bt_add_eep', n_clicks=0),#,style = {'width':'150px','height': '40px',}),
html.Br(),
html.Div(id='EEp_msg'),
html.H6('List of Entered Eating Episodes'),
dash_table.DataTable(
id='EEp_table',
columns=[{
'name': EEptable_col_desp[i-1],
'id': 'column-{}'.format(i),
'deletable': False,
'renamable': False
} for i in range(1, 4)],
data=get_updated_EEpdata(),
editable=True,
row_deletable=True,
style_cell = {
'font-family': 'cursive',
'font-size': '16px',
'text-align': 'center'
},
),
],style={'padding': 1, 'flex': '30%'})
layout = html.Div([
leftcol,
rightcol,
], style={'display': 'flex', 'flex-direction': 'row'})
return layout