I have a very basic need but I can't find any similar recent question. I have a big data table in my R Shiny app. When scrolling horizontally and / or vertically, I would need to do what we can easily do in excel, that is, freeze the first N columns and freeze the first N rows. My code below shows how to freeze the first 3 columns but I can't find a way to simultaneously freeze also the first 4 rows.
df <- datatable(df_data,
rownames= F,
filter = 'top',
#lengthChange = T,
extensions = c("Buttons","FixedColumns"),
caption = paste0("County Data."),
options = list(scrollX = TRUE
, autoWidth = TRUE
, pageLength = -1
, lengthMenu = list(c(5, 10, 15, 20, 25, -1), c('5', '10', '15', '20', '25', 'All'))
#, columnDefs = list(list(width = '200px', targets = c(0) ))
, initComplete = JS("function(settings, json) {","$(this.api().table().header()).css({'font-size': '12px'});","}")
, columnDefs = list(list(width = '200px', targets = c(0) ),
list(width = '50px', targets = c(1,2,3) ),
list(width = '100px', targets = c(seq(from = 3, to = dim(df_data)[2]-1)) ) )
, dom = 'Blfrtip'
, searching = T
, info = T
, fixedColumns = list(leftColumns = 3)
, buttons = c('copy', 'csv', 'excel', 'pdf')
))