DataTables

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v ggplot2 3.3.6     v purrr   0.3.4
## v tibble  3.1.8     v dplyr   1.0.9
## v tidyr   1.2.0     v stringr 1.4.1
## v readr   2.1.2     v forcats 0.5.2
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(DT)

First load the DT library with library(DT)

This document will use the mtcars data.

Options

Columns can be renamed, and with the extensions = "Buttons" option, the data can be downloaded. the extend = "collection" suboption allows for grouping, default file name, etc.

fileName <- "MTCars data"

mtcars %>% 
  arrange(desc(mpg), hp) %>% 
  datatable(
    caption = "MtCars Data",
    colnames = c("Car Name", "MPG", "# Cyl.", "Disp.", "HP", "Drat", "Wt", "1/4 Mile",
                 "vs", "am", "Gears", "Carb"),
    filter="top",
    extensions = 'Buttons', 
    options = list(
      dom = 'Bfrtip',
      buttons = list(
        'copy', 'print', list(
          extend = 'collection',
          buttons = list(
            list(extend = "csv", filename = fileName),
            list(extend = "excel", filename = fileName),
            list(extend = "pdf", filename = fileName)),
          text = 'Download')
      )
    )
  )