4

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.

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
Nate Thompson
  • 625
  • 1
  • 7
  • 22
  • 1
    You could create a [Div](https://bokeh.pydata.org/en/latest/docs/user_guide/interaction/widgets.html#div) element and update the content as you wish – ChesuCR Aug 23 '18 at 07:58
  • @ChesuCR Thanks, ill take a look at that. – Nate Thompson Aug 23 '18 at 12:01
  • It's helpful for the maintainers if [bokeh] questions that can be answered get answers. Using a `Div` is indeed an appropriate solution. Would one of you add that information as a real answer? – bigreddot Aug 23 '18 at 16:32
  • @ChesuCR or Nate, If you have the time it would be very helpful if you could post an answer with a minimal example of how to achieve this. – joelostblom Aug 05 '19 at 22:35
  • 1
    Sure @joelostblom, I will post something later – ChesuCR Aug 06 '19 at 12:34

1 Answers1

4

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])
)
ChesuCR
  • 9,352
  • 5
  • 51
  • 114