Quantcast
Channel: ЁЯОЫя╕П Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271
тЖз

How to add download pptx from link

$
0
0

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

3 posts - 2 participants

Read full topic

тЖз

Viewing all articles
Browse latest Browse all 6271

Trending Articles