dash-uploader icon indicating copy to clipboard operation
dash-uploader copied to clipboard

dev branch 0.7.0 598d05d not passing filenames

Open bpl-coding opened this issue 2 years ago • 2 comments

I am trying to use the 0.7.0 dev branch for its multi-file uploading enhancements.

The files are successfully uploaded, however, it does not appear that any filenames are being passed via callback. This is true even when only 1 file is uploaded.

I have switched to using the "uploadedFileNames" prop as it seems "isCompleted" and "filenames" are deprecated.

Am I doing something wrong?

@app.callback(
        Output("loaded-data", "data"),
        [
            Input("upload-data", "uploadedFileNames"),
            Input("confirm_clear_button", "n_clicks"),
        ],
        [
            State("upload-data", "upload_id"),
            State("loaded-data", "data"),
        ]
    )
    def update_data(filenames, confirm_clicks, upload_id, stored_results):
        UPLOAD_FOLDER_ROOT = r"du_files"

        trigger_id = dash.callback_context.triggered[0]["prop_id"].split(".")[0]
        if trigger_id == "confirm_clear_button":
            if confirm_clicks:
                return pd.DataFrame()
            else:
                raise PreventUpdate
        if trigger_id == "upload-data":
            print(filenames)
            #print(iscompleted)
            print(len(filenames))
            # if not iscompleted:
            #     return
            if filenames is not None and len(filenames) > 0:
                ###process files here####

[2022-03-29 20:56:33,279] DEBUG in httprequesthandler: File saved to: du_files\d8e79e88-3f60-4ae1-8312-e5f99dba5f11\Server_Results_20201221.log [] [2022-03-29 20:56:33,648] DEBUG in httprequesthandler: File saved to: du_files\d8e79e88-3f60-4ae1-8312-e5f99dba5f11\Server_Results_20201107.log [2022-03-29 20:56:34,011] DEBUG in httprequesthandler: File saved to: du_files\d8e79e88-3f60-4ae1-8312-e5f99dba5f11\Server_Results_20201208.log [2022-03-29 21:02:22,034] DEBUG in httprequesthandler: File saved to: du_files\5eabaf90-b53a-4782-9925-855bcde438e2\Server_Results_20201221.log [] [2022-03-29 21:02:22,750] DEBUG in httprequesthandler: File saved to: du_files\5eabaf90-b53a-4782-9925-855bcde438e2\Server_Results_20201208.log []

bpl-coding avatar Mar 30 '22 15:03 bpl-coding

Oh yeah, there has been a lot of changes in the 0.7.0 development branch which will unfortunately also have backwards-incompatible changes. I will have to document the things well when the release happens. I assume that you have built the JS yourself, which also might not been easy. As more people are trying the 0.7.0 I might as well go and make a pre-release available in PyPI so people can try it out without the NodeJS hassle.

Anyway, most probably the problem is with your callback structure. In the dev repo, the usage.py has a callback like this:

import dash_html_components as html
import dash_uploader as du


@du.callback(
    output=Output("callback-output", "children"),
    id="dash-uploader",
)
def callback_on_completion(status: du.UploadStatus):

    if status.n_uploaded == 0:
        return  # no files uploaded yet.

    print(status)

    out = []
    if status.uploaded_files is not None:
        return html.Ul([html.Li(str(x)) for x in status.uploaded_files])

    return html.Div("No Files Uploaded Yet!")

I should update the docs for the changes needed for the callbacks. The du.UploadStatus object is best described in Issue 68.

fohrloop avatar Mar 30 '22 20:03 fohrloop

I uploaded a pre-release version (0.7.0a1) to PyPi. You can install it with:

python -m pip install dash-uploader --pre

fohrloop avatar Mar 30 '22 20:03 fohrloop