Disable "FileDownload" button once user has downloaded the file
Hi, I would like to disable to "FileDownload" button once the user has downloaded the file but struggling to find a solution.
Something along these lines:
def DownloadFile(file_object, file_name):
def done():
download_available.value = False
if download_available.value == True: with solara.FileDownload(file_object, file_name, mime_type="application/vnd.ms-excel", on_done=done): solara.Button("Download the result Excel", icon_name="mdi-cloud-download-outline", color="success")
else: solara.Button(label="Output excel not ready", color="warning") "on_done" parameter is not part of "FileDownload" - just added it to demonstrate what I'd like to do. Any advice as how this could be achieved?
if download_available.value == True: with solara.FileDownload(file_object, file_name, mime_type="application/vnd.ms-excel", on_done=done): solara.Button("Download the result Excel", icon_name="mdi-cloud-download-outline", color="success")
else: solara.Button(label="Output excel not ready", color="warning") "on_done" parameter is not part of "FileDownload" - just added it to demonstrate what I'd like to do. Any advice as how this could be achieved?
6 Replies
Good question. We don't have an event for it, but this is a workaround that should work if the file is not too big:
if you pass in the data directly, it will not be uploaded lazily, and then this will probably work nicely
👍 OK, thank you for your suggestion. I'll give it a go. Should work as the excels in my case are relatively small.
Edit: Confirm, this solution works.
You could open an issue on GitHub so we can keep track of it
I think an on_done event makes sense
Opened Issue #769 in GitHub: https://github.com/widgetti/solara/issues/769
Helleeni
<:issue_open:882464248951877682> [widgetti/solara] An event to react to "FileDownload" component once the user has downloaded the file
This feature request was born out of need to disable to "FileDownload" button once the user has downloaded the file.
This was briefly discussed with Maarten in Discord: https://discord.com/channels/1106593685241614489/1169265343596867697/threads/1280504341278494780
The requested functionality would be something like this:
Where function done pointed by on_done parameter would be run once the user has downloaded the file.
Currently there doesn't seem to be any elegant way to do this (for workaround solutin refer to the Discord link).
Created
thank you @Helleeni !