How can I show and update a list of print statements in a Bokeh dashboard?

北战南征 提交于 2019-12-10 17:47:42

问题


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

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.


回答1:


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])
)


来源:https://stackoverflow.com/questions/51974510/how-can-i-show-and-update-a-list-of-print-statements-in-a-bokeh-dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!