cpaltemplates provides two table functions for different use cases:
cpal_table_reactable()
Interactive HTML
Dashboards, Shiny apps, web exploration
cpal_table_gt()
Static/Print
PDF reports, scientific publications, print materials
Both functions apply consistent CPAL branding: teal header borders, clean typography, and professional styling.
Need interactivity? (search, sort, filter, pagination) → Use cpal_table_reactable()
Need PDF/print output? → Use cpal_table_gt()
Small table in HTML report? → Use cpal_table_reactable(static = TRUE) for clean look without controls
Reactable Tables (Interactive)
Overview
cpal_table_reactable() creates interactive tables ideal for dashboards and web applications. Built on the reactable package, these tables offer:
Bootstrap 5 compatible - Works with bslib and modern Shiny dashboards
Interactive by default - Built-in search, sort, filter, and pagination
Responsive design - Adapts to different screen sizes
Accessible - Keyboard navigation and screen reader support
Styling Requirements
For full CPAL styling in different contexts:
Quarto docs
Include styles.css in _quarto.yml
Shiny (bslib)
Use cpal_dashboard_theme() - styling automatic
Shiny (basic)
Include cpal-theme.css in www/ folder
Basic Interactive Table
The default configuration creates a fully interactive table with search, pagination, and sorting.
mtcars |>
mutate (car = rownames (mtcars)) |>
select (car, mpg, cyl, hp, wt, qsec) |>
head (15 ) |>
cpal_table_reactable (
title = "Vehicle Database" ,
subtitle = "Sample from mtcars dataset" ,
source = "Motor Trend, 1974"
)
Static Mode
For small tables where interactivity isn’t needed, use static = TRUE to create a clean, print-friendly appearance while keeping CPAL styling. This disables search, pagination, sorting, and filtering.
mtcars |>
mutate (car = rownames (mtcars)) |>
select (car, mpg, cyl, hp, wt) |>
head (8 ) |>
cpal_table_reactable (
title = "Fuel Efficiency Summary" ,
subtitle = "Top 8 vehicles by MPG" ,
source = "Motor Trend, 1974" ,
static = TRUE
)
Static mode is ideal for: - Small reference tables (< 15 rows) - Tables embedded in HTML reports - Scientific/academic tables in web documents - Any situation where you want clean presentation without interactive controls
Built-in CPAL Styling
Tables created with cpal_table_reactable() automatically include CPAL branding:
Header
Bold text (1.1rem) with 2px teal borders (top and bottom)
Rows
Subtle teal highlight on hover, compact padding by default
Sorting
Click headers to sort (arrows hidden for clean look)
Striped rows
Light gray alternating background (when enabled)
Search input
Teal border with focus ring
Pagination
Styled page buttons with active state highlighting
Title/Subtitle
Consistent typography with CPAL colors
Source footer
Italicized attribution aligned right
Function Reference
cpal_table_reactable(
data,
title = NULL,
subtitle = NULL,
source = NULL,
static = FALSE,
searchable = TRUE,
pagination = TRUE,
page_size = 10,
sortable = TRUE,
filterable = FALSE,
striped = FALSE,
compact = TRUE,
...
)
Key Arguments
static
FALSE
Disable all interactive features for print-friendly output
searchable
TRUE
Enable global search bar
pagination
TRUE
Enable pagination
page_size
10
Rows per page
sortable
TRUE
Enable column sorting
filterable
FALSE
Enable per-column filtering
striped
FALSE
Enable zebra-striping for rows
compact
TRUE
Use reduced cell padding
Interactive Features
Column Filtering
Enable per-column filters for tables with categorical data:
mtcars |>
mutate (car = rownames (mtcars)) |>
select (car, mpg, cyl, hp, wt) |>
cpal_table_reactable (
title = "Filterable Table" ,
subtitle = "Use column filters to explore data" ,
filterable = TRUE ,
page_size = 10
)
Row Highlighting
Use bold_rows to highlight specific rows based on a condition:
mtcars |>
mutate (
car = rownames (mtcars),
high_performance = ifelse (hp > 200 , 1 , 0 )
) |>
select (car, mpg, cyl, hp, wt, high_performance) |>
head (15 ) |>
cpal_table_reactable (
title = "High Performance Vehicles" ,
subtitle = "Rows with HP > 200 are highlighted" ,
bold_rows = "high_performance" ,
page_size = 15
)
Striped Display
Add striped = TRUE for zebra-striping:
mtcars |>
mutate (car = rownames (mtcars)) |>
select (car, mpg, cyl, hp, wt, qsec, drat) |>
head (12 ) |>
cpal_table_reactable (
title = "Striped Table" ,
subtitle = "Zebra-striping for improved readability" ,
striped = TRUE ,
page_size = 12
)
GT Tables (Static/Print)
Overview
cpal_table_gt() creates publication-quality static tables using the gt package. These tables are designed for:
PDF reports - Clean rendering in PDF output
Scientific publications - Professional academic formatting
Print materials - Optimized for physical printing
Word documents - Compatible with docx export
GT tables share the same visual styling as reactable tables (teal header borders, consistent typography) but are optimized for static output formats.
Basic GT Table
mtcars |>
mutate (car = rownames (mtcars)) |>
select (car, mpg, cyl, hp, wt) |>
head (8 ) |>
cpal_table_gt (
title = "Vehicle Specifications" ,
subtitle = "Sample data from Motor Trend" ,
source = "Motor Trend, 1974"
)
Sample data from Motor Trend
Mazda RX4
21.0
6
110
2.620
Mazda RX4 Wag
21.0
6
110
2.875
Datsun 710
22.8
4
93
2.320
Hornet 4 Drive
21.4
6
110
3.215
Hornet Sportabout
18.7
8
175
3.440
Valiant
18.1
6
105
3.460
Duster 360
14.3
8
245
3.570
Merc 240D
24.4
4
62
3.190
Source: Motor Trend, 1974
GT Table with Striping
mtcars |>
mutate (car = rownames (mtcars)) |>
select (car, mpg, cyl, hp, wt) |>
head (10 ) |>
cpal_table_gt (
title = "Vehicle Data with Striping" ,
source = "Motor Trend, 1974" ,
striped = TRUE
)
car
mpg
cyl
hp
wt
Mazda RX4
21.0
6
110
2.620
Mazda RX4 Wag
21.0
6
110
2.875
Datsun 710
22.8
4
93
2.320
Hornet 4 Drive
21.4
6
110
3.215
Hornet Sportabout
18.7
8
175
3.440
Valiant
18.1
6
105
3.460
Duster 360
14.3
8
245
3.570
Merc 240D
24.4
4
62
3.190
Merc 230
22.8
4
95
3.150
Merc 280
19.2
6
123
3.440
Source: Motor Trend, 1974
Function Reference
cpal_table_gt(
data,
title = NULL,
subtitle = NULL,
source = NULL,
striped = FALSE
)
data
Data frame to display
title
Table title
subtitle
Table subtitle
source
Source attribution (prefixed with “Source:”)
striped
Enable zebra-striping (default: FALSE)
Extending GT Tables
Since cpal_table_gt() returns a gt object, you can chain additional gt functions:
mtcars |>
head (5 ) |>
cpal_table_gt (title = "Custom GT Table" ) |>
gt:: fmt_number (columns = mpg, decimals = 1 ) |>
gt:: cols_label (mpg = "Miles/Gallon" , hp = "Horsepower" )