Dash应用布局
后续的操作前,需要安装如下Python包
pip install dash==0.20.0 # The core dash backend
pip install dash-renderer==0.11.2 # The dash front-end
pip install dash-html-components==0.8.0 # HTML components
pip install dash-core-components==0.18.1 # Supercharged components
pip install plotly --upgrade # Plotly graphing library used in examples
使用Dash生成HTML
Dash应用包括两个部分,应用布局(layout)和数据交互(interactivity)。其中布局部分用来展示数据以及引导使用者使用。Dash提供了dash_core_components和dash_html_components, 以类的方式对HTML和JS进行封装,便于调用。下面先构建一个最简单的布局
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 frameworkd for Python.
'''),
dcc.Graph(
id = 'example-graph',
figure = {
'dash':[
{'x': [1,2,3], 'y':[4,1,2], 'type':'bar', 'name':'SF'},
{'x': [1,2,3], 'y':[2,4,5], 'type':'bar', 'name':'Montrel'},
],
'layout':{
'title':'Dash data Visualization'
}
}
)