Python 如何在bokeh中使用select小部件动态显示inputbox

Python 如何在bokeh中使用select小部件动态显示inputbox,python,charts,bokeh,Python,Charts,Bokeh,我试图在bokeh中根据用户输入实现图表,需求是级联下拉列表,以便根据下拉列表中的选定项显示文本框 如果我选择水果,它应该动态地询问输入的价格和数量 如果我选择human,它会动态地询问我姓名和年龄的输入 我是bokeh的新手请帮忙 提前感谢运行在bokeh服务器上的,您可以仅使用python代码以交互方式编辑任何对象属性。对于选择框,可以附加一个函数来检查选择菜单上的更改,然后在python函数中指定如何根据选定值更改输入对象。类似的东西 from bokeh.models import

我试图在bokeh中根据用户输入实现图表,需求是级联下拉列表,以便根据下拉列表中的选定项显示文本框

  • 如果我选择水果,它应该动态地询问输入的价格和数量
  • 如果我选择human,它会动态地询问我姓名和年龄的输入
我是bokeh的新手请帮忙
提前感谢运行在bokeh服务器上的

,您可以仅使用python代码以交互方式编辑任何对象属性。对于选择框,可以附加一个函数来检查选择菜单上的更改,然后在python函数中指定如何根据选定值更改输入对象。类似的东西

from bokeh.models import Select, TextInput
from bokeh.layouts import column, row

select = Select(options=["fruits", "human"], value="fruits")

text_input_1 = TextInput()
text_input_2 = TextInput()

layout = column(select, row(text_input_1, text_input_2))

def select_change(attrname, old, new):
    choice = new
    if choice == "fruits":
        text_input_1.title = "Price"
        text_input_2.title = "Quantity"

    elif choice == "human":
        text_input_1.title = "Name"
        text_input_2.title = "Age"

select.on_change('value', select_change)
您还可以在javascript中编写回调函数,将要修改的对象提供给回调函数,并在正在执行的javascript代码中对其进行修改。javascript选项的优点是不需要运行bokeh服务器

select.callback = CustomJS(args=dict(s=select, t_1=text_input_1, t_2=text_input_2), code="""
    if (s.value == "fruits") {
        t_1.title = "Price";
        t_2.title = "Quantity";
    }
    else if (s.value == "human") {
        t_1.title = "Name";
        t_2.title = "Age";
    }
""")

是否也可以动态更改显示的小部件?比如价格的滑块和名字的文本输入?@Philipp是的。如果要动态修改小部件的属性,小部件的类型应该无关紧要(slider、textinput)。我想更改小部件的类型。