散景 'single-value' 小部件
Bokeh 'single-value' widget
是否可以在 Bokeh 中创建如下所示的内容,或者这是否需要 customJS?似乎是一个相当简单的请求(至少就其他类似库提供的内容而言),但在文档中找不到任何内容。
要使用的核心 Bokeh 组件是 Div 对象。
template=("""
<div class='content'>
<div class='name'> {stock_name} </div>
<span class='number'>{price}<small>{price_unit}</small> </span>
<span class='percentage' style='color: {colour};'> {percentage}<small>%</small> </span>
</div>
""")
# initial text
text = template.format(stock_name = stock_name,
price=price,
price_unit='k',
percentage=percentage,
colour='#97D389')
div = Div(text=text, height=300)
然后可以将其添加到文档中并显示给用户。
作为一个完整的示例,我创建了一个示例要点,其中包含定期更新的数字 -
参见 https://gist.github.com/anthonydouc/c8571f0a2f9aa8415bd566e1ac2ba237。要点底部的评论中有关于如何构建应用程序的说明 - 创建一个名为 "stocktext" 的文件夹并按照指示构建子文件夹,然后 运行 'bokeh serve -- show stocktext'
示例输出:
大量使用流式示例 (https://demo.bokeh.org/surface3d),让数字自动更新。
整个内容只包含在一个简单的 html div 元素中,这里解释了 Bokeh 的用法:
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/widgets.html#div
最后,要启用基于 python 的回调,您需要 运行 散景服务器 - 请参阅 https://docs.bokeh.org/en/latest/docs/user_guide/server.html 了解更多信息。
是否可以在 Bokeh 中创建如下所示的内容,或者这是否需要 customJS?似乎是一个相当简单的请求(至少就其他类似库提供的内容而言),但在文档中找不到任何内容。
要使用的核心 Bokeh 组件是 Div 对象。
template=("""
<div class='content'>
<div class='name'> {stock_name} </div>
<span class='number'>{price}<small>{price_unit}</small> </span>
<span class='percentage' style='color: {colour};'> {percentage}<small>%</small> </span>
</div>
""")
# initial text
text = template.format(stock_name = stock_name,
price=price,
price_unit='k',
percentage=percentage,
colour='#97D389')
div = Div(text=text, height=300)
然后可以将其添加到文档中并显示给用户。
作为一个完整的示例,我创建了一个示例要点,其中包含定期更新的数字 -
参见 https://gist.github.com/anthonydouc/c8571f0a2f9aa8415bd566e1ac2ba237。要点底部的评论中有关于如何构建应用程序的说明 - 创建一个名为 "stocktext" 的文件夹并按照指示构建子文件夹,然后 运行 'bokeh serve -- show stocktext'
示例输出:
大量使用流式示例 (https://demo.bokeh.org/surface3d),让数字自动更新。
整个内容只包含在一个简单的 html div 元素中,这里解释了 Bokeh 的用法:
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/widgets.html#div
最后,要启用基于 python 的回调,您需要 运行 散景服务器 - 请参阅 https://docs.bokeh.org/en/latest/docs/user_guide/server.html 了解更多信息。