Dash与Flask结合实现多页面调转

from dash import Dash
from werkzeug.wsgi import DispatcherMiddleware
import flask
from werkzeug.serving import run_simple
import dash_html_components as html

server = flask.Flask(name)
dash_app1 = Dash(name, server = server, url_base_pathname='/dashboard/' )
dash_app2 = Dash(name, server = server, url_base_pathname='/reports/')
dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
@server.route('/')
@server.route('/hello')
def hello():
return 'hello world!'

@server.route('/dashboard')
def render_dashboard():
return flask.redirect('/dash1')

@server.route('/reports')
def render_reports():
return flask.redirect('/dash2')

app = DispatcherMiddleware(server, {
'/dash1': dash_app1.server,
'/dash2': dash_app2.server
})

run_simple('0.0.0.0', 8050, app, use_reloader=True, use_debugger=True)

werkzeug要升级到0.16以上,否则报错。

你可能感兴趣的:(Dash与Flask结合实现多页面调转)