# Interactive Tables

Oftern, it is useful to provide interactive tables alonside charts.
Responsive designed web content reflows itself dependent on the with of the browser window. There are many columns in the table which are over to the right-hand side and we need to scroll to access them.
So, could be really nice that the columns which don’t fit on the screen, are instead collapsed somehow, and optionally enable these.

library(tidyverse)
library(DT)
library(stringr)
transport_data <- read_csv("C:/07 - R Website/dataset/Graph/transport_data.csv")

pretty_headers <- gsub("[.]", " ", colnames(transport_data)) %>%
str_to_title()

transport_data %>%
datatable(
rownames = FALSE,
filter = list(position = "top"),
options = list(
dom = "lBfrtip",
buttons = I("colvis"),
language = list(sSearch = "Filter:"),
pageLength = 5,
autoWidth = TRUE,
columnDefs=list(list(width="200px",targets="_all")),
scrollX=TRUE
),
extensions = c("Buttons")
)

As we can see, We can horizontally and vertically scroll through the data. We get automatic pagination telling us about currently looking ar observations from 1 to 5 of 399 entries. We can also filter the data both globally and by column. There is also a very useful button called Column visibility that give us the possibility to include/exclude any variables. Last but not least, we can add a buttom to download the table in a .csv or Excel file format, here not included.