bokehtabulatorpandas-bokehtabulator-py

Convert panel.widgets.tables.Tabulator to layoutDOM


I'm new to Bokeh so apologies if I get the terminology wrong.

I have a simple dashboard and I'm trying to add a chart using tabulator to the page docs

The basic setup is as follows

from bokeh.models import Select, Panel  
from bokeh.models.widgets import Tabs

import my_func from irrelevant_code 

chart = my_func()  # this is a tabulator object

tab1 = Panel(child = summary_layout, title="Summary") 
tab2 = Panel(child = chart, title="Chart")
tabs = Tabs(tabs=[tab1, tab2])

document = curdoc()
document.add_root(tabs)

This runs into a problem since Panel expects a LayoutDOM object and chart is a panel.widgets.tables.Tabulator object.

How can I convert chart to a layoutDOM object?

The specific error I get is

*** ValueError: failed to validate Panel(id='1212', ...).child: expected an instance of type LayoutDOM, got Tabulator(formatters={'testDate': DateForm...}, groups={'testGroup': ['col1',...}, selectable='checkbox', selection=[0, 1, 2, 3, 4, ...], titles={'col1': 'Column 1', ...}, value=   val1 val2 v...) of type Tabulator

Solution

  • So while in theory you could use the .get_root() or .get_model() methods on the Tabulator to turn the Panel object into a Bokeh object I would generally recommend just sticking with Panel, e.g. your example can be written as:

    import panel as pn
    
    import my_func from irrelevant_code 
    
    chart = my_func()  # this is a tabulator object
    
    tabs = pn.Tabs(('Summary', summary_layout), ('Chart', chart))
    
    tabs.servable()