Creating interactive tables
interactive_tables.Rmd
For creating interactive tables, I recommend using reactable, which has excellent online documentation, and can be combined with reactablefmtr for additional ways of displaying the data within the tables.
The Ophelia package contains a reactable theme, which can be used as follows:
library(reactable)
head(palmerpenguins::penguins, 10) %>%
reactable(
theme = reactable_theme(),
pagination = FALSE,
striped = TRUE
)
head(palmerpenguins::penguins, 10) %>%
reactable(
theme = ophelia::reactable_theme(colour = "gold"),
pagination = FALSE,
striped = FALSE
)
Making use of {reactablefmtr
}, we can also do things
like this:
library(reactablefmtr)
head(palmerpenguins::penguins, 10) %>%
reactable(
theme = ophelia::reactable_theme(),
pagination = FALSE,
striped = TRUE,
columns = list(
body_mass_g = colDef(
cell = data_bars(palmerpenguins::penguins,
text_position = "outside-base",
fill_color = ophelia::ophelia_colours$purple,
number_fmt = function(x) format(x, big.mark = ","))
)
)
)
head(palmerpenguins::penguins, 10) %>%
reactable(
theme = ophelia::reactable_theme(colour = "dark_green"),
pagination = FALSE,
striped = TRUE,
columns = list(
body_mass_g = colDef(
cell = data_bars(palmerpenguins::penguins,
text_position = "outside-base",
fill_color = ophelia::ophelia_colours$light_blue,
number_fmt = function(x) format(x, big.mark = ","))
)
)
)
The tables can also be exported as html objects, for inclusion in a web page or presentation, or as images for inclusion as figures in a Word document.
formatted_table <- head(palmerpenguins::penguins, 10) %>%
reactable(
theme = ophelia::reactable_theme(colour = "dark_green"),
pagination = FALSE,
striped = TRUE,
columns = list(
body_mass_g = colDef(
cell = data_bars(palmerpenguins::penguins,
text_position = "outside-base",
fill_color = ophelia::ophelia_colours$light_blue,
number_fmt = function(x) format(x, big.mark = ","))
)
)
)
reactablefmtr::save_reactable(input = formatted_table,
output = "table.png")