from reactable import embed_css, Reactable, Column, ColFormat, ColFormatGroupBy
from reactable.data import us_states
embed_css()
Column aggregate cells
Column formatters can be applied to aggregated cells, produced by grouping data.
By default, formatters apply to both standard cells and aggregate cells.
= us_states
data
= ColFormat(suffix=" mi²", separators=True)
col_format
Reactable(
data,="Region",
group_by=[
columnsid="Area", aggregate="sum", format=col_format),
Column(
], )
Note that the data is collapsed, with aggregate cells displaying the total area per group. The formatter has applied the suffix mi²
to the aggregates.
Formatting aggregated cells
If you want to format aggregated cells separately, provide a named list of cell
and aggregated
options:
from reactable.models import ColFormatGroupBy
Column(format = ColFormatGroupBy(
= colFormat(...), # Standard cells
cell = colFormat(...) # Aggregated cells
aggregated
) )
For example, only the aggregated States
are formatted here:
= us_states
data
Reactable(
data,="Region",
group_by=[
columns
Column(id="States",
="count",
aggregateformat=ColFormatGroupBy(aggregated=ColFormat(suffix=" states")),
),id="Area", aggregate="sum", format=ColFormat(suffix=" mi²", separators=True)),
Column(
], )