代码之家  ›  专栏  ›  技术社区  ›  dnh37

Bokeh通知段落小部件--无法插入换行符

  •  0
  • dnh37  · 技术社区  · 7 年前

    from bokeh.io import curdoc
    from bokeh.models.widgets import Paragraph, Button
    from bokeh.layouts import row, widgetbox
    from bokeh.models import ColumnDataSource, Slider
    from bokeh.plotting import figure
    
    notifications = Paragraph(text='initial text')#, name=name, width=width, height=height)
    button = Button(label="Click me to add text")
    def callback():
        notifications.text += 'more text' + '\n'
    button.on_click(callback)
    
    # Set up layout and add to document
    box = widgetbox(notifications, button)
    curdoc().add_root(row(box))
    

    行中的“\n”

    notifications.text += 'more text' + '\n'
    

    不管它在不在那里,什么都不做。我也试过了

    notifications.text += 'more text' + '<br />'
    

    如果在这里解释html,但它不起作用。我还能尝试什么?

    1 回复  |  直到 7 年前
        1
  •  4
  •   bigreddot    5 年前

    我建议使用支持HTML的Div小部件,请参见

    https://docs.bokeh.org/en/latest/docs/reference/models/widgets.markups.html#bokeh.models.widgets.markups.Div

    然后,您的示例变成:

    from bokeh.io import curdoc
    from bokeh.models.widgets import Div, Button
    from bokeh.layouts import row, widgetbox
    from bokeh.models import ColumnDataSource, Slider
    from bokeh.plotting import figure
    
    notifications = Div(text='initial text')#, name=name, width=width, height=height)
    button = Button(label="Click me to add text")
    def callback():
        notifications.text += 'more text' + '</br>'
    button.on_click(callback)
    
    # Set up layout and add to document
    box = widgetbox(notifications, button)
    curdoc().add_root(row(box))