0
Select
위젯에서 선택한 값에 따라 Select
위젯에서 가능한 옵션을 조정하고 싶습니다. 내가 채식에 식품 그룹을 전환하는 경우에도,bokeh의 상호 의존적 위젯
from bokeh.io import output_notebook, show
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.models.widgets import Select
output_notebook()
# data source
foods = {'fruit': ['apple', 'orange', 'cherry'],
'veg': ['carrot', 'celery']}
source = ColumnDataSource(data=foods)
def change_options_in_choice2(source=source):
'''this is probably the place for magic'''
f = cb_obj.get('value')
print(f)
# first choice
choice1 = Select(title="food group:", value='fruit',
options=list(foods.keys()),
callback=CustomJS.from_py_func(change_options_in_choice2))
# options for second choice depend on choice in first choice
choice2 = Select(title='food items:', value='apple',
options=foods['fruit'])
# merge them
show(column(choice1, choice2))
, 난 단지 사과 사이에서 선택할 수 있습니다 오렌지, 또는 체리 내 음식 항목에 대한을 : 내 최소-작동하지 않는 예는 다음과 같다. 어쨌든,은 콜백을 사용하여 choice2
의 가능한 선택을 업데이트 할 수 있기를 바랍니다. choice1
. 어떻게하면 좋을까요?
새로운 옵션 목록에'.options'를 설정하십시오. 다음은 파이썬에서이를 수행하는 App 예제입니다 : https://github.com/bokeh/bokeh/blob/master/examples/app/stocks/main.py#L99-L105하지만 Principal은 CustomJS 콜백과 동일합니다 . – bigreddot
감사합니다 - 저를 위해 일했습니다. CustomJS에서이 작업을 수행하는 방법을 모르지만 bokeh 서버 솔루션이 내 용도로 적합합니다. – DrSAR