Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download prop to Button #528

Merged
merged 1 commit into from Feb 28, 2021
Merged

Add download prop to Button #528

merged 1 commit into from Feb 28, 2021

Conversation

tcbegley
Copy link
Collaborator

Add download prop to Button as requested in #526

@tcbegley
Copy link
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
Development

Successfully merging this pull request may close these issues.

None yet

1 participant