Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Only first callback in multiple callbacks work

Hi guys, I am building a multi-page app by Dash. I used the framework in (Structuring a Multi-Page App). On one page, I want to do file upload, after I select the files, the page will show filenames that selected, and after hitting the submit button, the program will do some process of the data and display result. The code is like following:

layout = html.Div([

    html.Div(html.H6('Please select files you want to upload:', style={'font-size':'15px','font-weight': 'bold'})),
    html.Div([dcc.Upload(['Drag and Drop or ', html.A('Select a File')],
              html.Button('Submit', id='button')]),


Output(‘to-be-upload-display’, ‘children’),
[Input(‘upload-file’, ‘filename’)])
def display_title(list_of_names):
print(“enter display_title”)
if list_of_names is not None:
children = [html.Div(html.H6(“To be uploaded files:”))]
file_list = [
html.Div([html.H6(name)]) for name in list_of_names
return children

Output(‘content-display’, ‘children’),
[Input(‘button’, ‘n_clicks’)],
[State(‘upload-file’, ‘contents’),
State(‘upload-file’, ‘filename’)])
def display_content(n_clicks, list_of_contents, list_of_names):
print(“enter function1”)
if list_of_contents is not None:
print(“enter function3”)
children = [html.Div(html.H6(“File Content:”))]
content_list = [
parse_contents(c, n) for c, n in zip(list_of_contents, list_of_names)
return children

The issue is everytime I run the app, only first callback works, there is no response after I hit the button. Does anyone know what the issue is?

Thanks a lot!

1 Like

I think I figure this out by putting all my callbacks under the file. It is the file that has
if name == ‘main’:

1 Like