r - 在 Shiny 中居中自定义数据表容器列标题

标签 r datatable shiny

我在这里遵循示例 2.5:https://rstudio.github.io/DT/在 shiny 中创建自定义数据表容器。该示例本身似乎运行良好。但是当我尝试在 Shiny 的应用程序中运行它时,萼片和花瓣 header 没有居中。请帮忙。谢谢。

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'

关于r - 在 Shiny 中居中自定义数据表容器列标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38544468/

相关文章:

r - R-Shiny 应用程序中的重音标记

javascript - 数据表作为全功能的表单元素

r - Shiny 评估两次

r - 如何捕获对 dplyr::select 中的 data.frame 所做的更改?

r - 在 ggplot2 中使用 ggrepel

c# - 如何从数据行中获取列?

SharePoint list.items.GetDataTable 列名称与字段名称不匹配

javascript - 如何在 Shiny 的仪表板侧栏中手动展开子菜单

r - 通过分配列聚合 data.frame 中的行

r - 尺度变换和坐标系变换有什么区别