Dash callback return Value

Hi
Thanks very much for the amazing tool.

I have a question on the return value of the callback function.
Suppose i have defined something like:

@app.callback(Output(),Input[,],State[,])
def func()

in the func, i use the input and states to do some calculations, and the results is saved to an excel file: D:\abc.xlsx

What I want is, the function returns the generated file with hyperlink or something, therefore I can click on the file to open it directly.

So, how to define the Output()? Or anything other idea?

thanks very much

X.w

If you create a Dash app like this:

app = Dash(__name__, static_folder='static')

And create a folder static in the same directory as the Python script, then the contents of that directory will be accessible via the web. So you can have you Dash callback create the excel file into that folder and then return the URL to the file. That URL will by default be /static/some_file.xlsx.

1 Like

Hi nedned, I’m probably late to the party. Just curious, for OP’s case, how should he/she write the decorator? I figured that in “Output()” you have to put some id of a widget right? How should I write it to return something to outside of Dash app (the caller basically)

I think you should be able to return an html.A tag that contains a link to the file. So the callback output would be the children property of some element.

Note that Dash has an enhanced method for serving static files now. See https://dash.plot.ly/dash-deployment-server/static-assets

1 Like