python - 通过 POST 请求接收图像数据后如何更新 Plotly 图?
问题描述
我想使用 Dash 应用程序显示通过远程客户端的 POST 请求上传的图像。我正在使用 Flask 路由来处理 POST 请求:
from dash import Dash
from flask import request
import dash_core_components as dcc
import numpy as np
import plotly.express as px
import cv2
app = Dash(__name__)
app.layout = dcc.Graph(id="graph")
@app.server.route("/images/upload", methods=["POST"])
def upload_image():
"""Upload an image via post request."""
if request.method == 'POST':
# check if the post request has the file part
data = request.data
if data:
nparr = np.fromstring(data, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
# this is the figure I want to load in the graph
fig = px.imshow(img)
# call a callback to update the graph component or update directly
# ...
# ...
return "OK"
我的问题是:有没有办法在从内部接收到图像数据后立即更新 Graph 组件upload_image()
?我知道我可以使用 Interval 组件,但我更愿意立即触发更新。
解决方案
推荐阅读
- javascript - 变量之间的共享值在 Angular 中不起作用
- python - 处理来自 python 请求的异常
- function - 为什么 PowerBuilder 函数 Integer("") 返回零
- python-3.x - 试图理解 keras 的分词器 texts_to_sequences
- linux - 从linux中的多个文件名中删除“-template”部分
- docker - kubernetes 无法从 docker-hub 的私有存储库中提取大图像
- windows-server-2016 - 如何测试安装了哪个版本的 Service Fabric Runtime
- spring-boot - CSS文件未在spring security中加载
- node.js - CORS 与谷歌 oauth
- php - SQL 查询忽略 WHERE online = '0'