python - 在 Plotly Dash 中显示后端日志消息
问题描述
我目前正在使用 Plotly Dash 为基于 JVM(Kotlin)的服务开发仪表板。本质上,JVM 服务将消息(通过 ZMQ)推送到我的 Python Dash 脚本,进而更新一系列实时图表。
除了图表,我还想在 Dash 仪表板中显示服务的日志消息(它们当前显示在控制台中并写入文件)。我可以轻松地修改 JVM 应用程序/Python 脚本以通过 ZMQ 发送/接收消息,但我一直无法找到可以实时显示这些消息的 Dash 组件。
由于消息的吞吐量非常高(每秒几十个),我希望能够按级别(信息、警告等)过滤消息,也许还有其他标准(正则表达式是理想的)。我阅读了 Dash 文档,但找不到适合我需要的组件。有没有办法在 Dash 中实现这一点?
谢谢你的帮助!
解决方案
我不熟悉您如何接收脚本中的消息,但您想要使用的是涉及以下内容的内容:
- 一个普通
html.Div(id='log-div',style=dict(height='300px',overflow='auto'))
的,只是一个可滚动的空 div - a
dcc.Interval
触发每 n 秒抓取一次新日志 - 一个看起来像的回调函数
@app.callback(
Output('log-div','children'),
[Input('log-interval','n_intervals')],
[State('log-div','children')]
)
def log_content(n_intervals,old_logs):
# take in the messages through some function
messages = receive_messages_function()
# filter the messages here
messages = filter_messages_function()
# old_logs is a list of the old messages, with each line being a
# separate div (to separate the messages, this can be done in many different ways).
# So what you do is add the new filtered messages to the old filtered messages
# Note - this assumes the messages are in a list of some sort; it doesn't matter
# as the concept is the same - just add the new messages after the old ones
messages = old_logs + messages
return messages
注意 - 旧的响应不正确。
希望这可以帮助!对任何问题/反馈发表评论,我很乐意回复。
推荐阅读
- jsp - 如何在 liferay 7.2 中覆盖 elasticSearch 的配置
- java - 在 thymeleaf html 中使用变量
- php - 我想在产品中进行自定义修改
- matlab - 脚本适用于键盘,但仅与响应按钮不一致
- python - 从 python 脚本运行进程,并且进程不应该停止
- python - 如何使用创建日期对子文件夹和文件的内容进行排序并在系统文件夹的 Windows 资源管理器中进行更改(排序依据)?
- ssl - SoapUI:连接已关闭:javax.net.SSLHandshakeException
- css - 生产版本覆盖了我在 .css 节点中的样式
- opayo - Sagpay 表单集成在测试环境中不起作用
- javascript - Socket.IO 服务器的奇怪行为