Plotly offline with flask

后端 未结 2 1739
误落风尘
误落风尘 2021-02-03 14:25

How can I use plotly offline with flask . I know that plotly can be used offline with Ipython notebook , Can I use Plotly offline with flask ? If not , can someone please sugges

2条回答
  •  隐瞒了意图╮
    2021-02-03 14:45

    Edit: Updated for current Plotly version

    What you want to do is make functions that return the offline "plot" result as a html

    . To do this, you call the offline.plot() method with the output_type="div" argument. This will return a pure string that you can then put in any flask template, and it will show the graph!

    Also, make sure to include the plotly.js library in your static files and link to them in your html pages that show graphs.

    This is an example of what I'm saying:

    import plotly.graph_object as go
    from plotly import io
    
    fig = go.Figure(data=barChart, layout=barLayout)
    
    div = io.to_html.plot(fig, show_link=False, output_type="div", include_plotlyjs=False)
    
    return div
    

提交回复
热议问题