指定组合框的位置

时间:2015-04-09 13:34:45

标签: python combobox bokeh

我有以下脚本生成一个组合框(Select)和一个情节:

import bokeh.plotting as bk
from bokeh.models import ColumnDataSource, Plot
from bokeh.models.widgets import Select
from bokeh.simpleapp import simpleapp

data = {"a": {"x": [1,2,3], "y": [1,2,3]},
        "b": {"x": [3,2,1], "y": [1,2,3]},
        "c": {"x": [2,2,2], "y": [1,2,3]},}


options = ["a", "b", "c"]
select1 = Select(name = 'ticker1', value = options[0], options = options)

@simpleapp(select1)
def test_layout(ticker1):
    p = bk.figure(title = "layout test")

    chart_data = data[ticker1]

    df = ColumnDataSource(data = chart_data)
    p.circle(x = chart_data["x"], y = chart_data["y"])

    return p

test_layout.route("/bokeh/layout/")

这很好用。但是,我发现无法指定组合框的位置。

我的目标是,组合框显示在情节上方(而不是左侧)。这怎么可能?

1 个答案:

答案 0 :(得分:1)

您可以通过实现实际构建布局的函数来自定义您的simpleapp布局,然后使用layout装饰器将其包装起来。在你的情况下,它是test_layout.layout装饰器。为此,您需要稍微更改代码。这是一个应该做你需要的版本:

import bokeh.plotting as bk
from bokeh.models import ColumnDataSource, Plot
from bokeh.models.widgets import Select, AppVBox
from bokeh.simpleapp import simpleapp

data = {"a": {"x": [1,2,3], "y": [1,2,3]},
        "b": {"x": [3,2,1], "y": [1,2,3]},
        "c": {"x": [2,2,2], "y": [1,2,3]},}


options = ["a", "b", "c"]
select1 = Select(name = 'ticker1', value = options[0], options =     options)

@simpleapp(select1)
def test_layout(ticker1):
    p = bk.figure(title = "layout test")

    chart_data = data[ticker1]

    df = ColumnDataSource(data = chart_data)
    p.circle(x = chart_data["x"], y = chart_data["y"])

    return {'plot': p}

@test_layout.layout
def layout(app):
    return AppVBox(app=app, children=['ticker1', 'plot'])

test_layout.route("/bokeh/layout/")