gpt4 book ai didi

select - Bokeh :初始创建后更新小部件

转载 作者:行者123 更新时间:2023-12-01 06:01:13 25 4
gpt4 key购买 nike

我正在尝试创建一个工具,允许用户选择不同的参数来绘制模型数据。我最初可以生成小部件,但我想根据用户的可能选择更新其中一个小部件。

Bokeh page

在此示例中,我将值“Phase”默认为“Water”,将“Effective Radius”默认为与 water-only 对应的值列表。如果用户从“阶段”中选择“冰”,我希望小部件从不同的值列表更新。这是相关的代码:

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 )

最佳答案

您的示例中缺少一些代码,所以我希望我正确理解您的问题:)。据我所知,当用户更改“云相”字段中的选择时,您希望更改“有效直径”字段中的选项。我认为要实现您想要的目标,您可以在 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)]

关于select - Bokeh :初始创建后更新小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45177180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com