简体   繁体   中英

Bokeh table widget with category names in the first column in each row and data in the next column

I want to create a Bokeh table widget with category names in the first column in each row and data in the second other column.

Is there a way to achieve this.

Thanks.

You can add everything you want to your table, as long as it's in your ColumnDataSource.

More information about tables can be found here .

from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral6
from bokeh.plotting import figure
from bokeh.transform import factor_cmap
from bokeh.models.widgets import DataTable, TableColumn
from bokeh.layouts import row

output_file("colormapped_bars.html")

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]

source = ColumnDataSource(data=dict(fruits=fruits, counts=counts))

p = figure(x_range=fruits, plot_height=250, toolbar_location=None, title="Fruit Counts")
p.vbar(x='fruits', top='counts', width=0.9, source=source, legend="fruits",
       line_color='white', fill_color=factor_cmap('fruits', palette=Spectral6, factors=fruits))

columns = [
    TableColumn(field="fruits", title="Fruits"),
    TableColumn(field="counts", title="Counts")
]
data_table = DataTable(source=source, columns=columns, width=400, height=280, index_position=None)

p.xgrid.grid_line_color = None
p.y_range.start = 0
p.y_range.end = 9
p.legend.orientation = "horizontal"
p.legend.location = "top_center"

show(row(p, data_table))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM