fohrloop / dash-uploader

The alternative upload component for python Dash applications.
MIT License
144 stars 30 forks source link

Uploading multiple files return only the first file #29

Closed nikky78 closed 2 years ago

nikky78 commented 3 years ago

Hi,

My code consists in the following:

# function to return all files in folder
def uploaded_files():
    files = []
    for filename in os.listdir(directory):
        file = os.path.join(directory, filename)
        files.append({'label': file, 'value': file})
    return files

### Layout
du.Upload(
    id='dash-uploader',
    filetypes=['csv', 'xls', 'xlsx'],
    max_files=2,
),

html.Div(id='callback-output', style={'display': 'none'})

dbc.Select(
    id="browse_content",
    placeholder="Select Data File",
    options=[],
),

### Callbacks
@du.callback(
    output=Output('callback-output', 'children'),
    id='dash-uploader'
)
def update_list(filenames):
    print('update_list', filenames)
    return filenames

@app.callback(
    [Output('browse_content', 'options')],
    [Input('callback-output', 'children')]
)
def get_a_list(files):
    filenames = uploaded_files()
    print('get_a_list', files, filenames)
    return filenames

But when uploading 2 files: file1.xlsx and file2.xlsx, I get the following print:

update_list ['C:\Users\file1.xlsx'] get_a_list ['C:\Users\file1.xlsx'] [{'label': 'file1.xlsx', 'value': 'file1.xlsx'}]

Both files have been uploaded in the folder, but it seems that callbacks stop after the first file being uploaded: even the line filenames = uploaded_files() in the callback "get_a_list" returns only the first file...

Any idea what's wrong here please?

Thanks!

fohrloop commented 3 years ago

Hi @nikky78,

Thanks for the detailed report. Do you think this could be same issue as in https://github.com/np-8/dash-uploader/issues/5 ?

sorenwacker commented 3 years ago

Which version was used here?

fohrloop commented 2 years ago

As there has been no activity here, I assume that this is duplicate of #5. Feel free to reopen, if you feel this is not the same issue.