Use the towny dataset to create a gt table with a header and a source note. Next, we add interactive HTML features through opt_interactive(). It’ll just be the default set of interactive options.
towny |> dplyr::select(name, census_div, starts_with("population")) |>gt() |>fmt_integer() |>cols_label_with(fn =function(x) sub("population_", "", x)) |>cols_width( name ~px(200), census_div ~px(200) ) |>tab_header(title ="Populations of Municipalities",subtitle ="Census values from 1996 to 2021." ) |>tab_source_note(source_note =md("Data taken from the `towny` dataset.")) |>opt_interactive()
Populations of Municipalities
Census values from 1996 to 2021.
name
census_div
1996
2001
2006
2011
2016
2021
Addington Highlands
Lennox and Addington
2,429
2,402
2,512
2,517
2,318
2,534
Adelaide Metcalfe
Middlesex
3,128
3,149
3,135
3,028
2,990
3,011
Adjala-Tosorontio
Simcoe
9,359
10,082
10,695
10,603
10,975
10,989
Admaston/Bromley
Renfrew
2,837
2,824
2,716
2,844
2,935
2,995
Ajax
Durham
64,430
73,753
90,167
109,600
119,677
126,666
Alberton
Rainy River
1,027
956
958
864
969
954
Alfred and Plantagenet
Prescott and Russell
8,315
8,593
8,654
9,196
9,680
9,949
Algonquin Highlands
Haliburton
1,687
1,827
1,976
2,186
2,351
2,588
Alnwick/Haldimand
Northumberland
5,528
5,846
6,435
6,617
6,869
7,473
Amaranth
Dufferin
3,450
3,770
3,845
3,963
4,079
4,327
1–10 of 414 rows
...
Data taken from the towny dataset.
Interactive tables can have styled body cells. Here, we use the gtcars dataset to create an interactive gt table. Using tab_style() and data_color() we can flexibly style body cells throughout the table.