用烧瓶离线离线

时间:2016-03-29 15:07:41

标签: flask plotly

如何在烧瓶中使用绘图离线。我知道可以使用Ipython笔记本离线使用,我可以使用Plotly离线使用烧瓶吗? 如果没有,有人可以建议我可以使用哪个python库进行烧瓶中的3D可视化(离线库)

2 个答案:

答案 0 :(得分:9)

你想要做的是制作返回离线的功能&#34; plot&#34;结果为html <div>。为此,使用output_type =&#34; div&#34;调用offline.plot()方法。论点。这将返回一个纯字符串,然后您可以将其放入任何烧瓶模板中,它将显示图形!

此外,请确保将plotly.js库包含在静态文件中,并在显示图形的html页面中链接到它们。

这是我所说的一个例子:

fig = go.Figure(data=barChart, layout=barLayout)

div = offplot.plot(fig, show_link=False, output_type="div", include_plotlyjs=False)

return div

答案 1 :(得分:4)

<强>更新

@DarenThomas 在我的使用中,我只是导入烧瓶并像往常一样创建路线。

import flask

# ... normal Dash stuff here

@app.server.route('/error.csv')
def serve_error():
    return flask.send_file('error.csv')

=============================================== ======================

对于那些展望未来的人,可以更新此答案以包括Plotly副项目Dash。它开箱即用,具有图形/烧瓶支持,非常容易获得现有的图形图形以显示在Web界面中。例如:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

另请参阅他们的tutorial series

相关问题