Bokeh or HoloViews multiple depended dropdowns

大城市里の小女人 提交于 2019-12-24 21:17:08

问题


I have a data set with 3 of the columns having categorical values. I want to create 3 drop downs in Bokeh or HoloViews in which the first drop down selection determines the values of the list in the other 2 drop downs. Can anyone point me to any of the tutorials or blog or docs that show how to this. I don't seem to fine any.​ I appreciate your time. Thanks!


回答1:


If you are working in a Jupyter notebook, you can use paramnb to do this, taking advantage of the way a notebook separates code into different cells:

Here I did "Run all", then selected c3 in the first widget, which re-runs the two cells below it to update them. I then selected a "high" value in the second set of widgets, which re-runs the plot to update it.

This pattern will let you do arbitrary chaining like this if you have notebooks, and if Jupyter Dashboards is an option for you then you can string these cells together to make an application. But this is just one approach...




回答2:


Here's an example where the values of one dropdown change dependent of the selection made in the other dropdown.
In the example, when you select a continent in one dropdown, the dropdown with possible countries changes in the other dropdown. This happens because of: @pn.depends(continent.param.value, watch=True)

import panel as pn

_countries = {
    'Africa': ['Ghana', 'Togo', 'South Africa'],
    'Asia'  : ['China', 'Thailand', 'Japan'],
    'Europe': ['Austria', 'Bulgaria', 'Greece']
}

continent = pn.widgets.Select(
    value='Asia', 
    options=['Africa', 'Asia', 'Europe']
)

country = pn.widgets.Select(
    value=_countries[continent.value][0], 
    options=_countries[continent.value]
)

# the countries dropdown is dependent on the continent dropdown
@pn.depends(continent.param.value, watch=True)
def _update_countries(continent):
    countries = _countries[continent]
    country.options = countries
    country.value = countries[0]

pn.Row(continent, country)

This holoviews + panel question has an example of dropdowns that are dependent on the value of another dropdown:
How do i automatically update a dropdown selection widget when another selection widget is changed? (Python panel pyviz)

The example with dropdowns dependent on other dropdowns comes from the GoogleMapViewer on this tutorial page: https://panel.pyviz.org/user_guide/Param.html



来源:https://stackoverflow.com/questions/47010764/bokeh-or-holoviews-multiple-depended-dropdowns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!