ui.download_button

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

Create a download button

Parameters

id: str

An id for the download.

label: TagChild

An input label.

icon: TagChild = None

An icon to display on the button.

width: Optional[str] = None

The width of the button.

**kwargs: TagAttrValue = {}

Additional attributes for the button.

Returns

Type Description
Tag A UI element

See Also

Examples

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400

## file: app.py
import asyncio
import random
from datetime import date

from shiny import App, Inputs, Outputs, Session, render, ui

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


def server(input: Inputs, output: Outputs, session: Session):
    @render.download(
        filename=lambda: f"æ–°åž‹-{date.today().isoformat()}-{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)