Hi All,
I am adding click functionality to download pptx file from given link but every time it is creating a blank pptx file below is sample code:
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
from dash.dependencies import Input, Output
from os import path
from flask import send_file
from pptx import Presentation
import io
app = dash.Dash(__name__,external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div([html.Div([html.A("Download PPT",href="/download_ppt/")],id = 'excel')])
#download cluster report
@app.server.route("/download_ppt/")
def download_excel():
if path.exists("insights.pptx"):
# Create DF
f=open('insights.pptx','rb')
prs=Presentation(f)
f.close()
#filename = io.BytesIO()
filename = io.StringIO()
prs.save(filename)
filename.seek(0)
return send_file(
filename,
mimetype = 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
attachment_filename="download.pptx",
as_attachment=True,
)
else:
raise PreventUpdate
if __name__ == "__main__":
app.run_server()