changed for pdf generation also
This commit is contained in:
7
app.py
7
app.py
@@ -29,15 +29,16 @@ def get_data():
|
|||||||
@app.route('/download-pdf')
|
@app.route('/download-pdf')
|
||||||
def download_pdf():
|
def download_pdf():
|
||||||
# Create Plotly graph
|
# Create Plotly graph
|
||||||
fig = go.Figure(data=[go.Scatter(x=[1, 2, 3], y=[10, 20, 30], mode='lines')])
|
#fig = go.Figure(data=[go.Scatter(x=[1, 2, 3], y=[10, 20, 30], mode='lines')])
|
||||||
|
df = px.data.stocks()
|
||||||
|
fig = px.line(df, x='date', y=['AAPL', 'GOOG'])
|
||||||
# Save the graph as an image
|
# Save the graph as an image
|
||||||
this_folder = os.path.dirname(os.path.abspath(__file__))
|
this_folder = os.path.dirname(os.path.abspath(__file__))
|
||||||
image_path = os.path.join(this_folder, 'static', 'graph.svg')
|
image_path = os.path.join(this_folder, 'static', 'graph.svg')
|
||||||
fig.write_image(image_path)
|
fig.write_image(image_path)
|
||||||
|
|
||||||
# Render the HTML template with the graph image
|
# Render the HTML template with the graph image
|
||||||
html = render_template('report.html', graph_image="file://" + image_path)
|
html = render_template('report.html', graph_image="file://" + image_path, table_data = df)
|
||||||
print(html)
|
print(html)
|
||||||
pdf = HTML(string=html).write_pdf()
|
pdf = HTML(string=html).write_pdf()
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Reference in New Issue
Block a user