shiny.ui.download_button#

shiny.ui.download_button(id, label, icon=None, width=None, **kwargs)#

Create a download button

Parameters
  • id (str) – An id for the download.

  • label (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – An input label.

  • icon (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – An icon to display on the button.

  • width (Optional[str]) – The width of the button.

  • kwargs (Union[str, float, bool, None]) – Additional attributes for the button.

Return type

A UI element

See also

download, download_link

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
import asyncio
from datetime import date

import numpy as np
from shiny import *

app_ui = ui.page_fluid(
    ui.download_button("downloadData", "Download"),
)

# For more examples of different types of download handlers, see:
# https://github.com/rstudio/py-shiny/blob/68ffc27/examples/download/app.py#L90
def server(input: Inputs, output: Outputs, session: Session):
    @session.download(
        filename=lambda: f"新型-{date.today().isoformat()}-{np.random.randint(100,999)}.csv"
    )
    async def downloadData():
        await asyncio.sleep(0.25)
        yield "one,two,three\n"
        yield "新,1,2\n"
        yield "型,4,5\n"

app = App(app_ui, server)