Rstudio 闪亮的 renderDataTable 标题多行? [英] Rstudio shiny renderDataTable headers multi line?
问题描述
我在 Rstudio Shiny 中有一个 renderDataTable
表,我用一些列构建了它,我想让标题变成多行,这样长的标题字符串就需要少量的水平空间.例如:
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.:
我的长标题列在我的 data.frame 中被称为 a_very_long_header
,使用下面的 colnames
技巧,我可以将它变成 a-very-long-header
,然后变成一个丑陋的多行标题:
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")
)
)
)
是否有更优雅的方法将 a_very_long_header
转换为 a very long header
以便它以多行方式打印标题?
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?
推荐答案
使用 HTML
library(shiny)
runApp(list(
server = 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<br>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)
})
}
, ui = navbarPage("Foo", id="page", collapsable=TRUE, inverse=FALSE,
tabPanel("Bar",
dataTableOutput("dt")
)
)
)
)
这篇关于Rstudio 闪亮的 renderDataTable 标题多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!