stremio中的交互式bokeh小部件

问题描述

我已经解决了这个问题一个星期,无法解决问题。我目前在Streamlit上有一段代码,在bokeh上有一些选项卡,例如:

import bokeh
import bokeh.layouts
import bokeh.models
import bokeh.plotting

#Tabs
tabs = bokeh.models.widgets.Tabs(
    tabs=[
        results(OPT),graphs(OPT),results_2(OPT),]
)
st.bokeh_chart(tabs)

只要我只显示数据就没有问题,但是我想(还有只有表格的“结果”标签)和另一个带有一些图形的标签可以过滤一些信息:

def graphs(OPT):
if OPT is not None:
    results = OPT.tabla_performance()
    source = bokeh.models.ColumnDataSource(results)
    template="""                
                <p style="font-size: 12px"> 
                    <%= (value).toFixed(2) +'%' %>
                </p>               
                """
    formatter =  bokeh.models.widgets.HTMLTemplateFormatter(template=template)        
    columns = [
        bokeh.models.widgets.TableColumn(field="Product",title="Product"),bokeh.models.widgets.TableColumn(field="Performance",title="Performance",formatter=formatter),]
    data_table = bokeh.models.widgets.DataTable(
        source=source,columns=columns,height=280,sizing_mode="stretch_width"
    )

    text = """
    <br>Performance graph
    """
    checkBox = bokeh.models.widgets.RadioButtonGroup(labels=["Total","By product"],active=0)
    if checkBox == "By product":
            checkBox_group = bokeh.models.widgets.CheckBoxButtonGroup(labels=["Option 1","Option 2","Option 3"],active=[])

    column = bokeh.layouts.Column(
        _markdown(text),data_table,checkBox,sizing_mode="stretch_width"
    )

return bokeh.models.Panel(child=column,title="Graphs")

我的问题出在以下几行:

    checkBox = bokeh.models.widgets.RadioButtonGroup(labels=["Total",active=[])

一个可以很好地显示两个选项,但是我无法像在普通Streamlit中那样使它具有动画效果。变量checkBox不会返回任何值,因此永远不会执行条件行。

我也尝试过使用callback选项将回调定义为:

checkBox = bokeh.models.widgets.RadioButtonGroup(labels=["Total",active=0,callback=bokeh.models.CustomJS.from_py_func(callback))

def callback(attr,old,new):
    bokeh.models.widgets.CheckBoxButtonGroup(labels=["Option 1",active=[])

但这似乎也不起作用。我的最终目标是使用复选框组中的这些选项,以在图形上显示不同的数据或最终触发另一个功能

有帮助/想法吗?

PS:添加最少的工作代码,目标是在“制图”选项卡中,一旦按下“按产品”按钮即可具有一个复选框列表,以便可以通过复选框选择来过滤图。

import datetime
import random

import bokeh
import bokeh.layouts
import bokeh.models
import bokeh.plotting
import markdown
import pandas as pd
import streamlit as st


def main():
st.title('Test')

tabs = bokeh.models.Tabs(
    tabs=[
        results(),graphs(),]
)
st.bokeh_chart(tabs)


def results():
N = 10
data = dict(
    dates=[datetime.date(2014,3,i + 1) for i in range(N)] * 100,downloads=[random.randint(0,100) for i in range(N)] * 100,)
source = bokeh.models.ColumnDataSource(data)

columns = [
    bokeh.models.widgets.TableColumn(
        field="dates",title="Date",formatter=bokeh.models.widgets.DateFormatter()
    ),bokeh.models.widgets.TableColumn(field="downloads",title="Downloads"),]
data_table = bokeh.models.widgets.DataTable(
    source=source,sizing_mode="stretch_width"
)
column = bokeh.layouts.Column(
    children=[data_table],sizing_mode="stretch_width"
)
return bokeh.models.Panel(child=column,title="Tables")

def graphs():
chart = bokeh.plotting.figure(sizing_mode="stretch_width",height=400)
chart.line([1,2,4,5],[6,7,line_width=3,color="navy",alpha=0.5)

checkBox = bokeh.models.widgets.RadioButtonGroup(labels=["Total",active=0)
if checkBox == "By product":
        checkBox_group = bokeh.models.widgets.CheckBoxButtonGroup(labels=["Option 1",active=[])

column = bokeh.layouts.Column(
    chart,sizing_mode="stretch_width"
)    

return bokeh.models.Panel(child=column,title="Plotting")

main()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)