Dash
目录依赖库
点击查看依赖库
black==22.8.0
Brotli==1.0.9
click==8.0.4
contextvars==2.4
dash==2.6.2
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
dataclasses==0.8
Flask==2.0.3
Flask-Compress==1.13
immutables==0.19
importlib-metadata==4.8.3
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
mypy-extensions==0.4.3
numpy==1.19.5
pandas==1.1.5
pathspec==0.9.0
platformdirs==2.4.0
plotly==5.10.0
python-dateutil==2.8.2
pytz==2022.2.1
six==1.16.0
tenacity==8.1.0
tomli==1.2.3
typed-ast==1.5.4
typing_extensions==4.1.1
Werkzeug==2.0.3
zipp==3.6.0
项目结构
项目大致分为两大部分 figures 部分读取数据生成各种图表,pages 定义报表格式,并嵌入 figures 的图表。
启动调试
Dash正常启动只能看到一个报表,现在通过 Flask 的 DispatcherMiddleware 处理,可以在一个项目内嵌入多个 Dash 报表。启动项目访问 http://127.0.0.1:8050/demo/ 可查看demo报表。
# main.py
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
from routes import ROUTES
from server import flask_server
application = DispatcherMiddleware(flask_server, ROUTES)
if __name__ == "__main__":
run_simple(
'127.0.0.1',
8050,
application,
use_reloader=True,
use_debugger=True
)
# routes.py
from pages.demo import dash_demo_app
ROUTES = {
'/demo_dash': dash_demo_app.server,
}
# pages/demo.py
import flask
from dash import Dash, html, dcc
from server import flask_server
dash_demo_app = Dash(
"dash_demo_app",
server=flask_server,
external_scripts=["https://tailwindcss.com/", {"src": "https://cdn.tailwindcss.com"}],
url_base_pathname="/demo/",
)
dash_demo_app.layout = html.Div([html.H1('I am dash_demo')])
@flask_server.route('/demo/')
def render_demo():
return flask.redirect('/demo_dash')
标签:dash,flask,Demo,server,Dash,demo,import,搭建
From: https://www.cnblogs.com/yingyu666/p/16737153.html