Download raw data with changing query

I’m looking for a way to add input to change a query to download data as an excel file. This is what I’ve got so far which works with a query in it but won’t allow me change the query.

Also this will be on a server not a local pc.

@app.server.route('/download_excel/')
def download_excel():
conn = pymysql.connect(
    host=host,
    user=user,
    password=password,
    db=db)
query = sqlquery
c = conn.cursor()
c.execute(query)
results1 = c.fetchall()
df = pd.DataFrame([[ij for ij in i]for i in results1]
strIO = io.BytesIO()
excel_writer = pd.ExcelWriter(strIO, engine="xlsxwriter")
df.to_excel(excel_writer, sheet_name="sheet1")
excel_writer.save()
excel_data = strIO.getvalue()
strIO.seek(0)
conn.close()
c.close()
return send_file(strIO,
                 attachment_filename='Data.xlsx',
                 as_attachment=True)
1 Like

I have the same needs