PlainDownloader
ClassComponentSource
comp = PlainDownloader(
id: str | Mapping[str, Any],
url: str,
loading_state: LoadingState
)
PlainDownloader
is a plain and native React component.
This component is implemented by a temporarily created magic link referring to a given URL.
Since the implementation of this PlainDownloader
is simply based on the HTML <a>
tag, the request headers and authentication of this downloader is not customizable.
Aliases
This type can be acquired by
import dash_file_cache as dfc
dfc.PlainDownloader
dfc.components.PlainDownloader
Component Properties
- Descriptions
- Properties
Name | Type | |
---|---|---|
id | str | Mapping[str, Any] | The ID of the component. A dictionary-id is used for creating a pattern-matching callback. |
url | str | The URL used to access the data to be downloaded. Each time when this value is set, a download event will be triggered. After triggering the download event, this value will be reset by a blank string. |
loading_state | LoadingState | The loading state set by Dash. This value should not be used by users. |
Name | Type | Interactive | Setable | Required | Default |
---|---|---|---|---|---|
id | str | Mapping[str, Any] | undefined | |||
url | str | "" | |||
loading_state | LoadingState | undefined |
- "Interactive" means that the property can be changed by users' interactions, thus firing a callback.
- "Setable" means that changing it by callback
Output(...)
will take effects. - "Required" means that the component cannot be initialized if this value is not explicitly provided.
Examples
Minimal example
- Codes
- Results
minimal_example_plain_downloader.py
from typing import Optional
import dash
import flask
from dash import html, Output, Input
from dash_file_cache.services.utilities import get_server
from dash_file_cache.components import PlainDownloader
app = dash.Dash("demo")
server = get_server(app)
app.layout = html.Div(
(html.Button(id="btn", children="Download"), PlainDownloader(id="downloader"))
)
@server.route("/file")
def file():
resp = flask.Response("test file content", status=200, mimetype="text/plain")
resp.headers["Content-Disposition"] = "attachment; filename=test.txt"
return resp
@app.callback(Output("downloader", "url"), Input("btn", "n_clicks"))
def trigger_get_file(n_clicks: Optional[int]):
if not n_clicks:
return dash.no_update
return "/file"
if __name__ == "__main__":
app.run()
An application with a downloading button will be rendered.
By clicking the button, a file named text.txt
will be downloaded, the file content is
test file content