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?
6 Replies
MaartenBreddels
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:
import asyncio
import solara
import solara.lab

download_available = solara.reactive(True)

@solara.lab.task
async def done():
# want a bit till it is downloaded
await asyncio.sleep(1)
download_available.value = False


@solara.component
def DownloadFile(file_object, file_name):

if download_available.value == True:
with solara.FileDownload(file_object, file_name, mime_type="application/vnd.ms-excel", ):
solara.Button("Download the result Excel", icon_name="mdi-cloud-download-outline", color="success", on_click=done)
else:
solara.Button(label="Output excel not ready", color="warning")


@solara.component
def Page():
DownloadFile('b123', 'test.txt')
import asyncio
import solara
import solara.lab

download_available = solara.reactive(True)

@solara.lab.task
async def done():
# want a bit till it is downloaded
await asyncio.sleep(1)
download_available.value = False


@solara.component
def DownloadFile(file_object, file_name):

if download_available.value == True:
with solara.FileDownload(file_object, file_name, mime_type="application/vnd.ms-excel", ):
solara.Button("Download the result Excel", icon_name="mdi-cloud-download-outline", color="success", on_click=done)
else:
solara.Button(label="Output excel not ready", color="warning")


@solara.component
def Page():
DownloadFile('b123', 'test.txt')
if you pass in the data directly, it will not be uploaded lazily, and then this will probably work nicely
Helleeni
Helleeni3w ago
👍 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.
MaartenBreddels
You could open an issue on GitHub so we can keep track of it I think an on_done event makes sense
Helleeni
Helleeni3w ago
Monty Python
Monty Python3w ago
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:
@solara.component
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")
@solara.component
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")
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
MaartenBreddels
thank you @Helleeni !
Want results from more Discord servers?
Add your server