@@ -605,10 +605,28 @@ async def transform(self, value: TagChild) -> Jsonifiable:
605605# ======================================================================================
606606# RenderDownload
607607# ======================================================================================
608+ @add_example (ex_dir = "../api-examples/download" )
608609class download (Renderer [str ]):
609610 """
610611 Decorator to register a function to handle a download.
611612
613+ This decorator is used to register a function that will be called when the user
614+ clicks a download link or button. The decorated function may be sync or async, and
615+ should do one of the following:
616+
617+ * Return a string. This will be assumed to be a filename; Shiny will return this
618+ file to the browser, and the downloaded file will have the same filename as the
619+ original, with an inferred mime type. This is the most convenient IF the file
620+ already exists on disk. But if the function must create a temporary file, then
621+ this method should not be used, because the temporary file will not be deleted by
622+ Shiny. Use the `yield` method instead.
623+ * `yield` one or more strings or bytestrings (`b"..."` or
624+ `io.BytesIO().getvalue()`). If strings are yielded, they'll be encoded in UTF-8.
625+ (This is better for temp files as after you're done yielding you can delete the
626+ temp file, or use a tempfile.TemporaryFile context manager) With this method, it's
627+ important that the `@render.download` decorator have a `filename` argument, as the
628+ decorated function won't help with that.
629+
612630 Parameters
613631 ----------
614632 filename
@@ -628,6 +646,7 @@ class download(Renderer[str]):
628646 See Also
629647 --------
630648 * :func:`~shiny.ui.download_button`
649+ * :func:`~shiny.ui.download_link`
631650 """
632651
633652 def auto_output_ui (self ) -> Tag :
0 commit comments