如何使用散景选择元素使滑块隐藏或不可见?

问题描述

This sample is altered from the bokeh example,sliders can control the bars in the figure. (sliders.py)

此示例是从bokeh示例中更改的,滑块可以控制图中的条。 (sliders.py) 在我的情况下,左侧有30多个滑块。似乎有些混乱,因此我尝试使用bokeh select元素连接滑块。目的是当我选择时,滑块区域将仅显示一个滑块。

我阅读了文档,有两种使用方法一个被禁用。如果为True,则小部件将显示为灰色,并且不响应UI事件。但是它不会隐藏。另一个可见,但出现属性错误: AttributeError(“对Slider意外的属性'可见',禁用了类似的属性“)

是否可以使散景滑块隐藏或不可见?还是有其他方法可以使滑块(超过30个)更清晰地区分?

这是可以在Jupyter笔记本中运行的代码

import bokeh.plotting.figure as bk_figure
from bokeh.io import curdoc,show
from bokeh.layouts import row,widgetBox
from bokeh.models import ColumnDataSource,Select
from bokeh.models.widgets import Slider,TextInput
from bokeh.io import output_notebook # enables plot interface in J notebook
import numpy as np
# init bokeh        
from bokeh.application import Application
from bokeh.application.handlers import FunctionHandler
    
    
output_notebook()
    
# Set up data
    
data = { 
    'line_x' : [1,2,3,4],'line_y' : [4,1],'bar_x':[1,'bar_bottom':[1,1,'bar_top':[0.2,2.5,3.7,}
   
#bar_color
determine_top = data['bar_top']
determine_bottom = data['bar_bottom']
determine_color = []
for i in range(0,4):
    if (determine_top[i] > determine_bottom[i]): 
        determine_color.append('#B3DE69') #green
    else:
        determine_color.append('firebrick')
    i+=1
data['determine_colors'] = determine_color
    
source = ColumnDataSource(data=data)
    
# Set up plot
plot = bk_figure(plot_height=400,plot_width=400,title="test",tools="crosshair,pan,reset,save,wheel_zoom",x_range=[0,10],y_range=[-5,5])
    
    plot.vbar(x='bar_x',width=0.5,top='bar_top',bottom='bar_bottom',source=source,color='determine_colors') 

# Set up widgets
select = Select(title="days_select:",options=["d1_select","d2_select","d3_select","d4_select"])

d1 = Slider(title="d1",value=0.0,start=-5.0,end=5.0,step=0.1)
d2 = Slider(title="d2",value=1.0,step=0.1)
d3 = Slider(title="d3",start=0.0,end=2*np.pi)
d4 = Slider(title="d4",start=0.1,end=5.1,step=0.1)


# Set up callbacks
def update_data(attrname,old,new):
    # Get the current slider values
    d1_value = d1.value
    d2_value = d2.value
    d3_value = d3.value
    d4_value = d4.value

    ##select
    #if select.value == "d2_select":
    #   d3.disabled = True
    #   d4.visible = False
    
    
    # Generate the new curve
    new_data = {
        'line_x' : [1,'bar_x': [1,'bar_bottom':[d1_value,d2_value,d3_value,d4_value],d1_value,d3_value],}
    
    #bar_color
    determine_top = new_data['bar_top']
    determine_bottom = new_data['bar_bottom']
    determine_color = []
    for i in range(0,4):
        if (determine_top[i] > determine_bottom[i]): 
            determine_color.append('green') #green
        else:
            determine_color.append('red')
        i+=1
    new_data['determine_colors'] = determine_color

    source.data = new_data
    
for w in [select,d1,d2,d3,d4]:
    w.on_change('value',update_data)

# Set up layouts and add to document
layout = row(widgetBox(select,d4),plot)

def modify_doc(doc):
    doc.add_root(row(layout,width=800))
    doc.title = "Sliders"

handler = FunctionHandler(modify_doc)
app = Application(handler)
show(app)

谢谢您的建议。

解决方法

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

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

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