Call a Flask function from a Dash callback


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().

How can we do this?

bouncing back this: anybody has any idea?

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

def download():
    return flask.send_file("filename.ext")

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

1 Like

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.

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?

1 Like