E-Dreamer

脚踏实地,仰望星空

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

本帖参考: https://blog.csdn.net/charizard90/article/details/105232590

Dash是一款用来搭建Web应用的Python框架,基于Flask,Plotly,js和React。
Dash的官网是https://dash.plotly.com/。
Dash的安装非常简单,直接通过pip install dash就能安装完成。

根据官网教程创建一个app.py。

# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

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)

运行python app.py
在浏览器中访问http://127.0.0.1:8050,第一个Dash应用就成功创建了。

image-20210201104518601

posted on 2021-02-01 11:01  E-Dreamer  阅读(845)  评论(0编辑  收藏  举报