Dash 嵌入 Flask App

Dash 有一个小秘密:它是在 Flask 的帮助下实现的。 事实上,Dash 实际上扩展了 Flask:每次我们制作 Dash 应用程序时,我们实际上都是在创建一个带有额外花里胡哨的 Flask 应用程序。 这听起来很合理,甚至可能令人兴奋:将 Plotly 的力量与 Flask 结合起来。

内容

  • Plotly和Flask结合制作
    • 最小的 Plotly Dash 应用程序 (代码)
  • 创建功能齐全的应用程序
    • Flask + Dash 实现(代码)
  • Flask 中的 Dash
    • 使用 Dash 初始化 Flask
      • wsgi.py
      • init.py
      • dashboard.py
      • 标准 Plotly Dash 初始化
      • Python 函数中的 Plotly Dash
  • 创建 Flask 主页
    • routes.py
    • index.jinja2
  • 创造用户浏览应用程序
    • dashboard.py
    • 在线演示应用:将 Dash 嵌入到您的 Flask 应用程序中
  • 源代码

详情参阅 - 亚图跨际

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个Python代码示例,使用Plotly Dash将仓储布局图嵌入到Web应用程序中,并实现上述功能: ```python import dash import dash_core_components as dcc import dash_html_components as html import plotly.graph_objects as go from dash.dependencies import Input, Output, State # 设置仓库大小和货架数量 n_rows = 5 n_cols = 4 # 创建仓库布局图 fig = go.Figure() # 添加仓库平面布局 fig.add_shape(type="rect", x0=0, y0=0, x1=n_cols, y1=n_rows, line=dict(color='black', width=2), fillcolor='white') # 添加货架 for i in range(1, n_rows + 1): for j in range(1, n_cols + 1): fig.add_shape(type="rect", x0=j - 0.5, y0=i - 0.5, x1=j + 0.5, y1=i + 0.5, line=dict(color='black', width=2), fillcolor='white') # 初始化货位颜色 colors = [['white' for _ in range(n_cols)] for _ in range(n_rows)] # 点击事件回调函数 def on_click(trace, points, state): # 获取点击的坐标 i, j = int(points.xs[0]), int(points.ys[0]) # 将货位标红 colors[i-1][j-1] = 'red' # 更新货位颜色 fig.data[0].update(dict(fillcolor=colors)) app = dash.Dash(__name__) app.layout = html.Div([ dcc.Graph( id='warehouse-layout', figure=fig ), html.Button('Reset', id='reset-button'), html.Div(id='selected-coordinates') ]) @app.callback( Output('warehouse-layout', 'figure'), Input('warehouse-layout', 'clickData'), State('warehouse-layout', 'figure') ) def update_layout(clickData, figure): if clickData: # 获取点击的坐标 i, j = int(clickData['points'][0]['y']), int(clickData['points'][0]['x']) # 将货位标红 colors[i-1][j-1] = 'red' # 更新货位颜色 figure['data'][0].update(dict(fillcolor=colors)) return figure @app.callback( Output('selected-coordinates', 'children'), Input('reset-button', 'n_clicks') ) def reset_colors(n_clicks): if n_clicks: # 重置货位颜色 global colors colors = [['white' for _ in range(n_cols)] for _ in range(n_rows)] # 更新货位颜色 fig.data[0].update(dict(fillcolor=colors)) return '' if __name__ == '__main__': app.run_server(debug=True) ``` 这段代码会创建一个Dash应用程序,其中包含一个嵌入的仓储布局图和一个重置按钮。当单击货位时,将该货位标记为红色,并在底部显示已选中的货位坐标。当单击重置按钮时,将重置所有货位的颜色。 要实现将储位连接形成最短路径,您可以使用有关路径规划的算法,并在Dash应用程序中实现该算法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值