在做项目的时候发现这个功能在官方文档中没有demo,网上博客的也很少,于是参考文档写了个大致的框架,其实dash的结构还是异步的处理方式,callback是数据处理的核心。
多页面布局
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
index_page = html.Div(children=[])
detail_page = html.Div(children=[])
@app.callback(dash.dependencies.Output('page-content', 'children'),
[dash.dependencies.Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/detail':
return detail_page
else:
return index_page
跳转链接
dcc.Link('', id="linking", href="/detail", style={"flaot": "left", "color": "black"})
@app.callback(
dash.dependencies.Output("linking", "href"),
[dash.dependencies.Input("select-filering", "value")])
def update_herf(filter_value):
url = "http://www.baidu.com"
return url