【发布时间】:2020-07-09 10:34:48
【问题描述】:
我的目标是在本地网络中的笔记本电脑上运行 Dash 应用程序,并从位于同一网络中的微控制器触发 HTTP 请求。这些请求应被 Dash 应用程序捕获,并应更新应用程序的布局。所以我的最终目标是为 Dash App 实现某种形式的远程控制。
当使用 Flask-server 并将其传递给 Dash-object 时,捕获 HTTP 请求是没有问题的:
import flask
import dash
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)
...
@server.route('/start_switch', methods=['GET'])
def start_switch():
print('server.route ran!')
# What do i run here to update layout-elements?
return Response('', 200)
...
但由于主要的交互性来自破折号回调,我不知道如何更新布局:
@app.callback(Output('show-status', 'children'),
[Input('app2-status', 'children')])
def watch_kalibrierung(app2_status):
"""
As soon as app2-status changes the function echoes
its contents to the in div 'show-status'
"""
return app2_status
因为现在,我不是在听 UI 元素的变化,而是在听 HTTP 请求。
我已经尝试过编写一个回调函数并从@server.route 函数中调用它,但是没有成功。
我怎样才能达到我想要的目标?
【问题讨论】:
标签: python user-interface flask request plotly-dash