如何在Bokeh仪表板中显示和更新打印语句列表? [英] How can I show and update a list of print statements in a Bokeh dashboard?

查看:83
本文介绍了如何在Bokeh仪表板中显示和更新打印语句列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建bokeh仪表板的一部分来显示p​​ython会话的控制台输出?

Is there a way to create a section of a bokeh dashboard that shows the console output from the python session?

我正在使用bokeh创建一个前端仪表板,该仪表板运行一个过程可能需要一段时间,并且会做很多事情.我想要一个部分来显示在执行过程中执行的一些打印语句.理想情况下,我希望有一个小部件类型的对象,该对象可以直接在仪表板上显示输出.

I am creating a front-end dashboard with bokeh that runs a process that can take a while and does a lot of stuff. I wanted a section that would show some of the print statements that are executed along the way. Ideally I was hoping for a little widget type object that could display the output directly within the dashboard.

推荐答案

一个简单的示例,它使用列表os消息的内容(带有html代码)更新Div元素.我认为您可以根据自己的需要进行调整:

Just a simple example updating a Div element with the content of a list os messages (with html code). I think you can adapt this to your needs:

from bokeh.layouts import column
from bokeh.io import curdoc
from bokeh.models import Button
from bokeh.models.widgets import Div

div = Div(
    text='',
    width=200,
    height=200
)

msg_list = []

def update_div():
    msg_num = len(msg_list)
    msg_list.append('{}: New message'.format(msg_num))
    m = ''
    for msg in msg_list:
        m += '<li>{}</li>'.format(msg)
    div.text = '<ul>{}</ul>'.format(m)

bt = Button(
    label="Update div",
    button_type="success",
    width=50
)

bt.on_click(update_div)

curdoc().add_root(
    column(children=[bt, div])
)

这篇关于如何在Bokeh仪表板中显示和更新打印语句列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆