本文介绍了在Shiny中将自定义数据表容器列标题居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里遵循示例2.5: https://rstudio.github.io/DT/以闪亮的方式创建自定义数据表容器.该示例似乎可以很好地运行.但是,当我尝试在闪亮的应用程序中运行它时,Sepal和Petal标头未居中.请帮忙.谢谢.
I'm following example 2.5 here: https://rstudio.github.io/DT/ to create a custom data table container in shiny. The example seems to work fine on its own. But when I try to run it in a shiny app, the Sepal and Petal headers are not centered. Please help. Thanks.
library(shiny)
runApp(list(
ui = basicPage(
h2('Iris Table'),
DT::dataTableOutput('mytable')
),
server = function(input, output) {
output$mytable = DT::renderDataTable({
# a custom table container
sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, 'Species'),
th(colspan = 2, 'Sepal'),
th(colspan = 2, 'Petal')
),
tr(
lapply(rep(c('Length', 'Width'), 2), th)
)
)
))
DT::datatable(iris[1:20, c(5, 1:4)], container = sketch, rownames = FALSE)
})
}
))
推荐答案
之前:
rowspan=2
添加此内容:
class = 'dt-center'
这篇关于在Shiny中将自定义数据表容器列标题居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!