In [1]:
# load bokehjs from locally built sources rather than the CDN
import os
os.environ['BOKEH_RESOURCES'] = 'inline'
In [2]:
from bokeh.io import output_notebook
output_notebook()
In [7]:
from bokeh.io import show
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, TableColumn, HTMLTemplateFormatter
from bokeh.sampledata.periodic_table import elements
elements['name_lower'] = elements['name'].str.lower()
source = ColumnDataSource(elements)
html_font_template = '<font color="<%= CPK %>"><%= value %></font>'
html_image_template = """
<a href="http://images-of-elements.com/<%= value %>.php" target="_blank">
<img src="http://images-of-elements.com/<%= value %>.jpg" style="width:40px;height:40px;border:0">
</a>
"""
columns = [
TableColumn(field='atomic number', title='Atomic Number'),
TableColumn(field='symbol', title='Symbol'),
TableColumn(field='name', title='Name',
formatter=HTMLTemplateFormatter(template=html_font_template)),
TableColumn(field='name_lower', title='Image',
formatter=HTMLTemplateFormatter(template=html_image_template))
]
data_table = DataTable(source=source, columns=columns, editable=False, row_height=45)
show(data_table)
In [ ]: