layout for multiple Data Table as children in each Bokeh Tab

橙三吉。 提交于 2020-01-16 08:06:07

问题


I want to have several tables inside each Bokeh Tab (Bokeh Panel)

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)


回答1:


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')



回答2:


The width and height are optional args for Div. If you just create a dumbdiv object without these args, you will get a div inserted in-between p1 & p2 without any specific width or height.

dumbdiv = Div()
l1 = layout([[p1, dumbdiv, p2], [p3]], sizing_mode='fixed')

So, now you should see enough space between p1 & p2:



来源:https://stackoverflow.com/questions/54693284/layout-for-multiple-data-table-as-children-in-each-bokeh-tab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!