How to refresh page after upload

I have an upload button that uploads a file. It works fine.

dbc.Col(dcc.Upload(html.Button(‘Upload CTM’),
id=‘hist-upload’), width={‘size’: 2})]),

I have a callback that is triggered on the file contents and file name.

I want to have the page refresh after the upload so I tried this:

dbc.Col(html.A(dcc.Upload(html.Button(‘Upload CTM’),
id=‘hist-upload’),
href=’/history-version’), width={‘size’: 2})

However, it does not work like I want it to. It seems to immediately refresh the page, then I get the upload file selection dialog but the file is never uploaded. It appears to trigger the callback before the file selection dialog even shows up. Since I haven’t even selected a file, the file contents and filename is None.

Without the html.A around the upload the upload works as desired but the page is not refreshed.

How can I get both to happen? 1. upload the file and 2. refresh the page

You could try to add a dcc.Location(id="url") component in the app and use Output("url", "pathname") in the callback to upload the files. Then if you return "/" (and refresh=True`), the page would refresh if the upload is complete.

Thank you. Yes, that did work. It is a multipage app though so I did not use ‘/’. I used the url for that page. I guess only one page could refresh this way since we can only have one output for the same id? How would I do it if I wanted to refresh more than one page?

In that case, you could merge all logic into one callback (with appropriate branching, depending on what input triggered the callback), or you could use the MultiplexerTransform,