每个“散景"选项卡中作为子级的多个数据表的布局 [英] layout for multiple Data Table as children in each Bokeh Tab
问题描述
I want to have several tables inside each Bokeh Tab (Bokeh Panel)
但是,桌子水平地连接在一起,我找不到一种很好地显示它们的方法.我使用了一个哑的Div作为快速解决方案,但是它创建了太多的空间,甚至是宽度为1的Div.我该如何实现?这是我的代码:
However, the tables get attached together horizontally and I don't find a way to nicely show them. I used a dumb Div as a quick solution but it created too much space, even a Div with width=1. How shall I achieve this? Here is my code:
from bokeh.models.widgets import Panel, Tabs, TableColumn,DataTable, Div
import numpy as np
from bokeh.io import output_notebook, show
from bokeh.models import ColumnDataSource
from bokeh.layouts import row, column, layout
output_notebook()
columns = [
TableColumn(field="A", title="A"),
TableColumn(field="B", title="B"),
TableColumn(field="C", title="C"),
TableColumn(field="D", title="D"),]
data1 = {"A":np.random.randint(23, 89, 10),
"B": np.random.randint(23, 89, 10),
"C": np.random.randint(23, 89, 10),
"D": np.random.randint(23, 89, 10)}
source1 = ColumnDataSource(data1)
p1 = DataTable(source=source1, columns=columns, width=300, height=200,editable=True)
data2 = {"A":np.random.randint(23, 89, 10),
"B": np.random.randint(23, 89, 10),
"C": np.random.randint(23, 89, 10),
"D": np.random.randint(23, 89, 10)}
source2 = ColumnDataSource(data2)
p2 = DataTable(source=source2, columns=columns, width=300, height=200,editable=True)
data3 = {"A":np.random.randint(23, 89, 10),
"B": np.random.randint(23, 89, 10),
"C": np.random.randint(23, 89, 10),
"D": np.random.randint(23, 89, 10)}
source3 = ColumnDataSource(data3)
p3 = DataTable(source=source3, columns=columns, width=300, height=200,editable=True)
dumbdiv = Div(text=""" """,
width=1, height=20)
l1 = layout([[p1, p2], [p3]], sizing_mode='fixed')
# l1 = layout([[p1, dumbdiv, p2]], sizing_mode='fixed')
tab1 = Panel(child=l1, title="Three Tables")
tabs = Tabs(tabs=[tab1],sizing_mode='scale_width')
show(tabs)
结果如下:(第一张表的滚动条未显示;我希望第一行的表之间有一些空间)
This is the result: (scroll bar of the first table is not showing; I want some space between the tables at the first row)
推荐答案
Div()的问题在于两个数据表之间可能存在相当大的差距,远远超过了需要.我认为使用Spacer看起来更好
The problem with Div() is there can be considerable gap between two datatables-much more than needed.I think using Spacer looks better
row2 = row(p1, Spacer(width=600, height=10), p2)
l1 = layout([row2], sizing_mode='fixed')
这篇关于每个“散景"选项卡中作为子级的多个数据表的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!