指定组合框的位置 [英] Specify position of combo box

查看:61
本文介绍了指定组合框的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下脚本,该脚本生成一个组合框( Select )和一个绘图:

I have the following script that generates a combo box (Select) and a plot:

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/")

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

This works just fine. However, I found no possibility to specify the position of the combo box.

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

My goal is, that the combo box is displayed above the plot (and not on the left side). How is this possible?

推荐答案

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

You are able to customize your simpleapp layout by implementing a function that actually builds your layout and then wrap it with the layout decorator. In your case it'd be test_layout.layout decorator. To do so you need to change the code a bit. Here's a version that should do what you need:

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/")

这篇关于指定组合框的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆