diff --git a/holoviews/plotting/bokeh/tabular.py b/holoviews/plotting/bokeh/tabular.py index 15f5ce4e34..b24d3a704f 100644 --- a/holoviews/plotting/bokeh/tabular.py +++ b/holoviews/plotting/bokeh/tabular.py @@ -70,9 +70,23 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): source = self._init_datasource(data) self.handles['source'] = source + columns = self._get_columns(element, data) + style['reorderable'] = False + table = DataTable(source=source, columns=columns, height=self.height, + width=self.width, **style) + self.handles['plot'] = table + self.handles['glyph_renderer'] = table + self._execute_hooks(element) + self.drawn = True + + for cb in self.callbacks: + cb.initialize() + + return table + + def _get_columns(self, element, data): columns = [] - dims = element.dimensions() - for d in dims: + for d in element.dimensions(): col = dimension_sanitizer(d.name) kind = data[col].dtype.kind if kind == 'i': @@ -89,21 +103,10 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): else: formatter = StringFormatter() editor = StringEditor() - column = TableColumn(field=d.name, title=d.pprint_label, + column = TableColumn(field=dimension_sanitizer(d.name), title=d.pprint_label, editor=editor, formatter=formatter) columns.append(column) - style['reorderable'] = False - table = DataTable(source=source, columns=columns, height=self.height, - width=self.width, **style) - self.handles['plot'] = table - self.handles['glyph_renderer'] = table - self._execute_hooks(element) - self.drawn = True - - for cb in self.callbacks: - cb.initialize() - - return table + return columns def update_frame(self, key, ranges=None, plot=None): diff --git a/tests/plotting/bokeh/testtabular.py b/tests/plotting/bokeh/testtabular.py index 1c8b2b795c..49da787ba7 100644 --- a/tests/plotting/bokeh/testtabular.py +++ b/tests/plotting/bokeh/testtabular.py @@ -42,6 +42,13 @@ def test_table_plot(self): self.assertIsInstance(column.formatter, fmt) self.assertIsInstance(column.editor, edit) + def test_table_plot_escaped_dimension(self): + table = Table([1, 2, 3], ['A Dimension']) + plot = bokeh_renderer.get_plot(table) + source = plot.handles['source'] + renderer = plot.handles['glyph_renderer'] + self.assertEqual(list(source.data.keys())[0], renderer.columns[0].field) + def test_table_plot_datetimes(self): table = Table([dt.now(), dt.now()], 'Date') plot = bokeh_renderer.get_plot(table)