File size: 1,129 Bytes
5dd4d14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Source: https://awesome-panel.org/resources/table_of_elements_with_wikipedia_row_content/
"""

import panel as pn
from bokeh.sampledata.periodic_table import elements

pn.extension("tabulator")

@pn.cache
def get_elements():
    return elements[
        ["atomic number", "name", "atomic mass", "metal", "year discovered"]
    ].set_index("atomic number")

periodic_df = get_elements()

@pn.cache # Caching is a hack to avoid flickering. It seems like row content is loaded twice otherwise
def content_fn(row):
    return pn.pane.HTML(
        f'<iframe src="https://en.wikipedia.org/wiki/{row["name"]}" width="100%" height="500px"></iframe>',
        sizing_mode="stretch_width"
    )

periodic_table = pn.widgets.Tabulator(
    periodic_df,
    layout="fit_columns",
    sizing_mode="stretch_both",
    row_content=content_fn,
    embed_content=True,
)

pn.template.FastListTemplate(
    site="Awesome Panel",
    site_url="https://awesome-panel.org",
    title="Table of Elements with Wikipedia row content",
    main=[periodic_table],
    accent="#F08080",
    main_layout=None,
    main_max_width="1024px",
).servable()