Skip to content

Add download prop to Button - #528

Merged
tcbegley merged 1 commit into
mainfrom
button-download-prop
Feb 28, 2021
Merged

Add download prop to Button#528
tcbegley merged 1 commit into
mainfrom
button-download-prop

Conversation

@tcbegley

Copy link
Copy Markdown
Collaborator

Add download prop to Button as requested in #526

@tcbegley
tcbegley force-pushed the button-download-prop branch from 38c4515 to d1c9a3f Compare February 28, 2021 09:06
@tcbegley

Copy link
Copy Markdown
Collaborator Author

Here's an example. With the following directory structure

.
├── app.py
└── file.txt

and the following contents in app.py.

# app.py
from pathlib import Path

import dash
import dash_bootstrap_components as dbc
import flask

HERE = Path(__file__).parent

app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dbc.Container(
    dbc.Button(
        "Download",
        href="/file.txt",
        download="test.txt",
        external_link=True,
    ),
    className="p-5",
)


@app.server.route("/file.txt", methods=["GET"])
def send_file():
    return flask.send_from_directory(HERE, "file.txt")


if __name__ == "__main__":
    app.run_server(debug=True)

text file can be anything, just to test downloads.

@tcbegley
tcbegley merged commit babfb0e into main Feb 28, 2021
@tcbegley
tcbegley deleted the button-download-prop branch February 28, 2021 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant