Reset DataTable selection

As described here, there seems to be no mechanism to remove a selection in a DataTable object. Example follows:

import pandas as pd
from bokeh.io import output_file, save
from bokeh.layouts import layout
from bokeh import models as bmd
from bokeh.plotting import figure

def create_bokeh_datatable(src, width, height):
    col_names = {'u': 'U',
                 'v': 'V'}

    template="""<b><div><%= (value).toFixed(0) %></div></b>"""
    f = bmd.HTMLTemplateFormatter(template=template)
    cols = [bmd.TableColumn(field=x, title=col_names[x], formatter=f)
            for x in ['u', 'v']]
    table_opt = dict(width=width, height=int(0.7*height), source=src)
    table = bmd.DataTable(columns=cols, **table_opt)
    return table
            
def plot(df):
    width, height = 600, 600

    source = bmd.ColumnDataSource(df)
    arru = source.data['u']
    arrv = source.data['v']

    hover_opt = dict(hover_fill_color='black', hover_line_color='black',
                     hover_line_width=4, hover_alpha=0.2)
    hvr_tt = [('u,v', '@u,@v')]
    p = figure(width=width, height=height, tools='pan,save,reset')

    r = p.rect(x='u', y='v', source=source,
               width=1., height=1.,
               width_units='data', height_units='data',
               fill_color='red', line_color='black', line_width=3,
               **hover_opt)
    p.text(arru, arrv,
           text=['u,v={},{}\n'.format(u,v) for (u, v) in zip(arru, arrv)],
           text_baseline='middle', text_align='center',
           text_font_size='16pt')

    p.add_tools(bmd.HoverTool(tooltips=hvr_tt, renderers=[r]))

    table = create_bokeh_datatable(source, width, height)
    
    lay = layout([[p, table]])

    output_file('tmp.html')
    save(lay)


df = pd.DataFrame({'u': [1,2,3,3], 'v': [2,3,3,4]})
plot(df)

Once the user clicks on a table entry, the only way to revert to the previous state is to click on the “Reset” button in the figure. Is there any way to do the same directly in the table?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.