# Call a Flask function from a Dash callback

**URL:** <https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075>\
**Category:** Dash Python\
**Created:** [February 25, 2019, 2:27pm UTC](https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075 "2019-02-25T14:27:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abeserra](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Abeserra](https://community.plotly.com/u/Abeserra)\
**Post date:** [February 25, 2019, 2:27pm UTC](https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075/1 "2019-02-25T14:27:50Z")

</div>

Hi.

So we have this user case that we want to return a file to the user when they press a button.

The event would trigger a Dash callback and then we just want to call to [`flask.send_file()`](http://flask.pocoo.org/docs/1.0/api/?highlight=send_file#flask.send_file).

How can we do this?

---

<div class="post-metadata">

**Author:** ![Abeserra](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Abeserra](https://community.plotly.com/u/Abeserra)\
**Post date:** [February 28, 2019, 3:36pm UTC](https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075/2 "2019-02-28T15:36:02Z")

</div>

bouncing back this: anybody has any idea?

---

<div class="post-metadata">

**Author:** ![tcbegley](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@tcbegley](https://community.plotly.com/u/tcbegley)\
**Post date:** [February 28, 2019, 3:51pm UTC](https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075/3 "2019-02-28T15:51:08Z")

</div>

You can define routes on the underlying Flask server of your Dash app, so something like this will do the trick

```python
@app.server.route("/download")
def download():
    return flask.send_file("filename.ext")

```

Then just add a link to your layout with `href="/download"`.

---

<div class="post-metadata">

**Author:** ![Abeserra](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Abeserra](https://community.plotly.com/u/Abeserra)\
**Post date:** [February 28, 2019, 4:33pm UTC](https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075/4 "2019-02-28T16:33:41Z")

</div>

We already do that, but we want to use more parameters and data which are given by other dash components, so we need to get them inside a dash callback and return the file from there.

---

<div class="post-metadata">

**Author:** ![nedned](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nedned/32/8795_2.png) [@nedned](https://community.plotly.com/u/nedned)\
**Post date:** [March 1, 2019, 4:56am UTC](https://community.plotly.com/t/call-a-flask-function-from-a-dash-callback/20075/5 "2019-03-01T04:56:25Z")

</div>

Maybe the callback could select the right link (selecting from all possible links which have already been created with flask routes) and return that, updating the layout?
