tabulator with collapsed row_content by default

Here is a tabulator with row_content:
https://vcu-ssg.github.io/ssg-quarto-soc-analysis/31_explore.html

I’d like the row_content to be collapsed on loading. An older version of panel had this default. Since upgrading the code my row_content is expanded on loading.

Here is the creation code:

df_widget = pn.widgets.Tabulator(
    summary_df,
    show_index = False,
    sorters=[
        {'field':'Wrkld','dir': 'desc'},
        {'field':'Hours','dir': 'desc'},
    ],
    widths={'Hour Bar':'20px','Wrkld Bar':'15px'},
    titles={'Hour Bar':'Lecture/total hours','Wrkld Bar':'Total/Lecture wrkld'},
    sortable={'Hour Bar':False,'Wrkld Bar':False},
    header_filters=filters,
    formatters={
        'Crse': NumberFormatter( format="0.0",text_align='center'),
        'CRNs': NumberFormatter( format="0.0",text_align='center'),
        'Stdnts': NumberFormatter( format="0.0",text_align='center'),
        'Hours': NumberFormatter( format="0.0",text_align='center'),
        'Hr.Lec': NumberFormatter( format="0.0",text_align='center'),
        'Wrkld': NumberFormatter( format="0.00",text_align='center'),
        'W.Lec': NumberFormatter( format="0.00",text_align='center'),
        'Wrkld Bar': {'type':'html'},
        'Hour Bar': {'type':'html'}
    },
    row_content=content_fn,
    embed_content=True,
    expanded = [],
    selection = []
)

Note that I’m setting expanded to .

Suggestions?

Can you share a minimal, reproducible example (MRE)?

In general, a complete script only with the essential code, which can be copied/pasted and immediately run as-is with no modifications. This is much more useful than snippets.

I’ll work on it. Before investing all that time, I was hoping that someone had encountered this issue and could offer a quick fix! The “expanded = ” argument doesn’t seem to work. I’m thinking that it’s operator error (me) and not a bug in the software, so an MRE won’t reveal a bug. But, we shall see. Time to code!

1 Like

Here is a sample code block.

Desired behaviors

  • Row contents should be collapsed on start.
  • Row contents displayed and hidden when triangle toggled.

Observed behaviors

  • row contents are expanded on start
  • row contents are not displayed when triangle is toggled.
import pandas as pd
import panel as pn

pn.extension('tabulator')

# sample dataframe
data = {'name': ['Alice', 'Bob', 'Charlie'],
        'Value1': [10, 20, 30],
        'Value2': [3, 2, 5],
        }
df = pd.DataFrame(data)

# function to return row contents
def content_fn( row ):
    return pn.pane.Markdown(
        f'# Row contents\n name: {row["name"]}',
        sizing_mode='stretch_width'
    )

# tabulator object with row_contents
sample_table = pn.widgets.Tabulator(
    df, height=350,
    layout='fit_columns',
    sizing_mode='stretch_width',
    row_content=content_fn,
    embed_content=True,
    expanded = []
)

sample_table

Looks like a bug, can you report the Bug on Github?

Done! see: https://github.com/holoviz/panel/issues/7361

Solved by Address issues with Tabulator embed_content and optimize row expansion by philippjfr · Pull Request #7364 · holoviz/panel · GitHub