-
Notifications
You must be signed in to change notification settings - Fork 117
Closed
Description
The render.download docs don't include a description of what the decorated function is supposed to be/do.
Here's the basic facts. There are two different ways the decorated function can provide data to Shiny:
- Return a string. This will be assumed to be a filename; Shiny will return this file to the browser, and the downloaded file will have the same filename as the original, with an inferred mime type. This is the most convenient IF the file already exists on disk. But if the function must create a temporary file, then it shouldn't be used; the temporary file will not be deleted by Shiny... use one of the other methods instead.
yieldone or more strings or bytestrings (b"..."orio.BytesIO().getvalue()). If strings are yielded, they'll be encoded in UTF-8. (This is better for temp files as after you're done yielding you can delete the temp file, or use a tempfile.TemporaryFile context manager) With this method, it's important that the@render.downloaddecorator have afilenameargument, as the decorated function won't help with that.
The decorated function can be sync or async.
One method is not currently supported but would be really nice: the decorated function could opt to take an argument that's a file-like object, provided by Shiny. This makes e.g. matplotlib.pyplot.savefig much easier to call; as it is, you have to savefig into a BytesIO, then get the value out.
Metadata
Metadata
Assignees
Labels
No labels