构建具有复杂布局的Bokeh面板的示例?

时间:2016-06-09 14:19:40

标签: python bokeh

我正在尝试制作具有相对复杂布局的Bokeh面板,因此我尝试将当前布局的一半移动到一个Panel而将一半移动到另一个只是为了玩耍,就像这样:

selects = HBox(top_users_select, new_users_select, t1_users_select, t2_users_select, top_recent_users_select)
tab1 = Panel(inputs)
tab2 = Panel(VBox(HBox(plot2, plot1, plot3, plot4), HBox(plot5, plot6, plot7, plot8), data_table))
tabs = tabs(tab1, tab2)
show(tabs)

然而,这给了我以下错误:

File "main_panel.py", line 589, in <module>:
tab1 = Panel(inputs) Traceback (most recent call last):
  File "/Users/joe/anaconda3/lib/python3.5/site-packages/bokeh/application/handlers/code_runner.py", line 71, in run
    exec(self._code, module.__dict__)
  File "/Users/joe/Desktop/scripts/src/main/python/Bokeh apps/insights/main_panel.py", line 589, in <module>
    tab1 = Panel(inputs)
TypeError: __init__() takes 1 positional argument but 2 were given

我对Bokeh很新,看着我不知道如何解析这个错误并绕过它的文档。 有人能指出我在Bokeh面板中布置相当复杂的网格的示例,或者告诉我错误意味着什么以及如何解决它?

2 个答案:

答案 0 :(得分:1)

我想你想写selects而不是inputs,但你的宣言基本上有些问题。

查看http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/widgets.html#tab-panes

上的示例
from bokeh.models.widgets import Panel, Tabs
from bokeh.io import output_file, show
from bokeh.plotting import figure

output_file("slider.html")

p1 = figure(plot_width=300, plot_height=300)
p1.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
tab1 = Panel(child=p1, title="circle")

p2 = figure(plot_width=300, plot_height=300)
p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5)
tab2 = Panel(child=p2, title="line")

tabs = Tabs(tabs=[ tab1, tab2 ])

show(tabs)

您在Panel中的输入应该分配到child=,而Panel需要title=

同时更改

 tabs = tabs(tab1, tab2)

tabs = Tabs(tabs=[tab1,tab2,tab3,tab4])

答案 1 :(得分:1)

您可以使用rowcolumn在标签内创建复杂的布局。 您甚至可以像row(column(button1, button2), button3)

一样混合它们

示例

from bokeh.models.widgets import Panel, Tabs, Toggle, TextInput
from bokeh.io import output_notebook, show
from bokeh.plotting import figure

from bokeh.layouts import column, row  

p1 = figure(plot_width=300, plot_height=300)
p1.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)

p2 = figure(plot_width=300, plot_height=300)
p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5)

toggle1 = Toggle(label="Foo", button_type="success")
toggle2 = Toggle(label="Foo", button_type="warning")
text_input = TextInput(value="default", title="Label:")

tab1 = Panel(child=row(p1,toggle2), title="circle")
tab2 = Panel(child=column(p2,toggle, text_input), title="line")

tabs = Tabs(tabs=[ tab1, tab2 ])
output_notebook()
show(tabs)

有关更多详细信息,请参见https://bokeh.pydata.org/en/latest/docs/reference/layouts.html