I have a shiny DataTable (package "DT") with quite long column names (+ whitespace) that I want to be rendered without name wrapping - i.e. colnames wrapped over 2-3 lines. I have enabled horizontal scrolling to try and facilitate this:
renderDataTable(dataframe_with_long_colnames, ..., options = list(scrollX = TRUE))
but by default the whitespace is collapsed to new lines.
I think this answers my question: https://www.datatables.net/forums/discussion/8923/how-do-you-stop-the-header-from-wrapping-into-multiple-rows but I'm not sure how to translate this to the R function.
In addition, all DataTable options are listed here: https://www.datatables.net/reference/option/
Thanks in advance.
In ui.R add the following line before the line where you render the table:
tags$head(tags$style("#table1 {white-space: nowrap; }")),
Replace table1
with xxxxx
from your output statement in server.R
file
output$`xxxxx`<-renderDataTable(.....
You can simply use the nowrap
class:
library(DT)
dat <- data.frame(
"This is a looooooooooooooooonnnnnnnnnnnnggggggg column name" = c(1,2),
"This is also a looooooooooooooooooonnnnnnnnnnnggggggg column name" = c(3,4),
check.names = FALSE
)
datatable(dat, class = "display nowrap")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With