rh1
January 10, 2024, 9:11am
1
Hi all,
kindly please advice how to showing row content with show data selected in tabulator format, I try to follow as per documentation but there is an error.
Code
import panel as pn
from bokeh.sampledata.periodic_table import elements
pn.extension ('tabulator')
periodic_df = elements[['atomic number', 'name', 'atomic mass', 'metal', 'year discovered']].set_index('atomic number')
content_fn1 = lambda row: pn.pane.HTML(
f'<iframe src="https://en.wikipedia.org/wiki/{row["name"]}?printable=yes" width="100%" height="200px"></iframe>',
sizing_mode='stretch_width'
)
content_fn = lambda row: pn.widgets.Tabulator(elements,selection={row["name"]})
periodic_table = pn.widgets.Tabulator(
periodic_df, height=350, layout='fit_columns', sizing_mode='stretch_width',
row_content=content_fn, embed_content=True
)
periodic_table
error message:
ValueError: List parameter 'BaseTable.selection' must be a list, not an object of <class 'set'>.
thanks
selection={row["name"]}
I think needs to be a list. Wrapping it in {}
without a colon makes it a set.
rh1
January 11, 2024, 4:25pm
3
Hi @ahuang11 thanks for your advise, however I don’t get what you mean. kindly please give any example probably?
thanks
ValueError: List parameter 'BaseTable.selection' must be a list, not an object of <class 'set'>.
x = {1} is a set
x = [1] is a list
rh1
January 12, 2024, 3:43am
5
thanks @ahuang11 for your explanation. Unfortunately tabulator still couldn’t show row content with tabulator format.
basically I want to display another dataframe or subset from dataframe inside that row content.
thanks
import panel as pn
from bokeh.sampledata.periodic_table import elements
pn.extension("tabulator")
periodic_df = elements[
["atomic number", "name", "atomic mass", "metal", "year discovered"]
].set_index("atomic number")
content_fn1 = lambda row: pn.pane.HTML(
f'<iframe src="https://en.wikipedia.org/wiki/{row["name"]}?printable=yes" width="100%" height="200px"></iframe>',
sizing_mode="stretch_width",
)
content_fn = lambda row: pn.widgets.Tabulator(elements, selection=[int(row.name)])
periodic_table = pn.widgets.Tabulator(
periodic_df,
height=350,
layout="fit_columns",
sizing_mode="stretch_width",
row_content=content_fn,
embed_content=True,
)
periodic_table
rh1
January 13, 2024, 2:02am
7
Perfect , thanks @ahuang11 . Will try to show only relevant data since currently all dataframe content still show up.
2 Likes
Marc
January 14, 2024, 10:46am
8
Hi @rh1
I’m still trying to understand what you end goal is. Would it be something like the below?
import panel as pn
from bokeh.sampledata.periodic_table import elements
pn.extension("tabulator")
periodic_df = elements[
["atomic number", "name", "atomic mass", "metal", "year discovered"]
].set_index("atomic number")
content_fn = lambda row: pn.pane.HTML(
f'<iframe src="https://en.wikipedia.org/wiki/{row["name"]}?printable=yes" width="100%" height="400px"></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="Panel", title="Tabulator Table with `row_content`", main=[periodic_table], accent="Purple"
).servable()
rh1
January 14, 2024, 12:29pm
9
hi @Marc thanks for your code. actually my goal is to display more detail data from dataframe when user click the row in the tabulator, instead we get something information from external info in this example information with the key is the row (atom name) from outside website, now we display more detail from ourself dataframe or database.
So there is combining between selection([Tabulator — Panel v1.3.6 ]) and content (https://panel.holoviz.org/reference/widgets/Tabulator.html#row-contents but the content is from the selection dataframe one.
is it possible @Marc , kindly please advise.
my code
import panel as pn
from bokeh.sampledata.periodic_table import elements
pn.extension("tabulator")
periodic_df = elements[
["atomic number", "name", "atomic mass", "metal", "year discovered"]
].set_index("atomic number")
content_fn2 = lambda row: pn.widgets.Tabulator(elements, selection=[int(row.name)-1])
selection_data=content_fn2.selected_dataframe
periodic_table = pn.widgets.Tabulator(
periodic_df,
height=350,
layout="fit_columns",
sizing_mode="stretch_width",
row_content=selection_data,
embed_content=True,
)
a=pn.Row(periodic_table)
a.show()
still have error
what my goal is:
thanks
dleybel
January 15, 2024, 6:58pm
10
I think this is what you’re looking for.
Alternatively, I think you can achieve the same with a filter.
import panel as pn
from bokeh.sampledata.periodic_table import elements
pn.extension("tabulator")
periodic_df = elements[
["atomic number", "name", "atomic mass", "metal", "year discovered"]
].set_index("atomic number")
content_fn2 = lambda row: pn.widgets.Tabulator(elements.loc[[int(row.name)-1]])
periodic_table = pn.widgets.Tabulator(
periodic_df,
height=350,
layout="fit_columns",
sizing_mode="stretch_width",
row_content=content_fn2,
embed_content=True,
)
a=pn.Row(periodic_table)
a.show()
1 Like
rh1
January 16, 2024, 3:28am
11
Perfect @dleybel , that’s what I am looking for. Many thanks.