Issue
There is a simple flask app which writes statistics-table from db to a page. How can I plot plotly.express chart on this page? Code for chart that I want to integrate to a flask app: (took from https://plotly.com/python/time-series/)
# Using plotly.express
import plotly.express as px
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/...')
fig = px.line(df, x='Date', y='AAPL.High')
fig.show()
Solution
i think to do this is a little more complicated to just call a fig.show()
, take a fast look in the ploty lib i found this packet import dash_html_components as html
with this you can return a html with your chart to put in web site,
from flask import Flask
app = Flask(__name__)
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
@app.route('/chart')
def chart():
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/...')
fig = px.line(df, x='Date', y='AAPL.High')
return html.Div([dcc.Graph(figure=fig)])
Answered By - Caio Filus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.