我尝试创建一个工具,允许用户选择不同的参数来绘制模型数据。我最初可以生成小部件,但我想根据用户的可能选择更新其中一个小部件。
在这个例子中,我违反了价值"阶段"到" Water"和"有效半径"到与仅与水相对应的值列表。如果用户选择" Ice"来自"阶段",我希望从不同的值列表更新窗口小部件。以下是相关代码:
from bokeh.models.widgets import (Slider, Button, CheckboxGroup,
RadioButtonGroup, RadioGroup, Dropdown, Select)
# Selector for phase.
#--------------------
phs = [ "Water", "Ice", "Clear" ]
phs_select1 = Select( title="Cloud Phase", value=phs[0], options=phs,
width=150 )
phs_select2 = Select( title="Cloud Phase", value=phs[0], options=phs,
width=150 )
def update_phs( flag ):
if flag == 0:
fname[flag,3] = phs_select1.value.lower()
update_de_list( )
de_select1.update()
if flag ==1:
fname[flag,3] = phs_select2.value.lower()
update_de_list( )
phs_select1.on_change( 'value', lambda attr, new, old: update_phs(0) )
phs_select2.on_change( 'value', lambda attr, new, old: update_phs(1) )
# Selector for effective diameter.
#----------------------------
de = [np.str(x) for x in (8, 20, 32, 50)]
def update_de_list():
# Add something here to update the widget?
?????????????????????????
if phs_select1.value.lower() == "water":
de = [np.str(x) for x in (8, 20, 32, 50)]
elif phs_select1.value.lower() == "ice":
de = [np.str(x) for x in (21.86, 46.34, 115.32)]
????????????????????????????????????
?
? Once user has selected a different phase, I need to update
? "Effective Diameter field.
?
?????????????????????????
de_select1= Select( title="Effective Diameter", value=de[0], options=de,
width=150 )
de_select2 = Select( title="Effective Diameter", value=de[0], options=de,
width=150 )
def update_de( flag ):
if flag == 0:
fname[flag,5] = "de"+de_select1.value
if flag == 1:
fname[flag,5] = "de"+de_select2.value
de_select1.on_change( 'value', lambda attr, new, old: update_de(0) )
de_select2.on_change( 'value', lambda attr, new, old: update_de(1) )
# Layout the widgets for the first file
lft_pnl = [srf_select1,igbp_select1,tau_select1,ws_select1,aod_select1]
rgt_pnl = [ prf_select1, phs_select1, de_select1, cld_select1 ]
lft_col = WidgetBox( *lft_pnl, sizing_mode="fixed", width=150)
rgt_col = WidgetBox( *rgt_pnl, sizing_mode="fixed", width=150)
# Layout the widgets for the first file
lft_pnl = [srf_select2,igbp_select2,tau_select2,ws_select2,aod_select2]
rgt_pnl = [ prf_select2, phs_select2, de_select2, cld_select2 ]
lft_col2 = WidgetBox( *lft_pnl, sizing_mode="fixed", width=150)
rgt_col2 = WidgetBox( *rgt_pnl, sizing_mode="fixed", width=150)
pnl_layout = layout([[lft_col, rgt_col],[lft_col2,rgt_col2],[plt_button]])
l = layout(children=[[grid,pnl_layout]])
curdoc().add_root( l )
答案 0 :(得分:0)
您的示例中缺少一些代码,因此希望我能正确理解您的问题:)。据我所知,当用户更改“云相”字段中的选择时,您想更改“有效直径”字段中的选项。我认为,要实现您想要的目标,可以只在update_de_list()回调中替换以下行:
de = [np.str(x) for x in (21.86, 46.34, 115.32)]
具有:
de_select1.options = [np.str(x) for x in (21.86, 46.34, 115.32)]
de_select2.options = [np.str(x) for x in (21.86, 46.34, 115.32)]