I have a renderDataTable
table in Rstudio Shiny that I build with some columns I want to have the header going multi-line, so that a long header string takes a small amount of horizontal space. E.g.:
My long header column is called a_very_long_header
in my data.frame, and with the colnames
trick below I can turn it into a-very-long-header
, which then turns into an ugly multi-line header:
shinyServer(function(input, output, session) {
output$dt <- renderDataTable({
data = data.frame(a_very_long_header=rnorm(10),a=rnorm(10),b=rnorm(10),c=rnorm(10),d=rnorm(10),e=rnorm(10),f=rnorm(10),g=rnorm(10),h=rnorm(10),i=rnorm(10),j=rnorm(10),k=rnorm(10),a1=rnorm(10),b1=rnorm(10),c1=rnorm(10),d1=rnorm(10),e1=rnorm(10),f1=rnorm(10),g1=rnorm(10),h1=rnorm(10),i1=rnorm(10),j1=rnorm(10),k1=rnorm(10))
colnames(data) = c("a-very-long-header","a","b","c","d","e","f","g","h","u","j","k","a1","b1","c1","d1","e1","f1","g1","h1","u1","j1","k1")
return(data)
})
})
shinyUI(navbarPage("Foo", id="page", collapsable=TRUE, inverse=FALSE,
tabPanel("Bar",
dataTableOutput("dt")
)
)
)
Is there a more elegant way to turn a_very_long_header
into a very long header
so that it prints the header in multi-line?