【问题标题】:Center custom data table container column headers in Shiny在 Shiny 中居中自定义数据表容器列标题
【发布时间】:2016-11-27 10:06:35
【问题描述】:

我在这里遵循示例 2.5:https://rstudio.github.io/DT/ 在闪亮中创建自定义数据表容器。该示例本身似乎可以正常工作。但是当我尝试在闪亮的应用程序中运行它时,Sepal 和 Petal 标题没有居中。请帮忙。谢谢。

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)

  })
}
))

【问题讨论】:

    标签: r datatable shiny


    【解决方案1】:

    之前:

    rowspan=2
    

    添加这个:

    class = 'dt-center'
    

    【讨论】:

      【解决方案2】:

      在你的 UI 中,添加这个标签:

      runApp(list(
          ui = basicPage(
              tags$head(
                  tags$style(type = "text/css",
                     HTML("th { text-align: center; }")
                  )
              ),
          h2('Iris Table'),
          DT::dataTableOutput('mytable')
          )
      

      【讨论】:

        猜你喜欢
        • 2019-02-08
        • 2013-08-06
        • 2019-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-02
        相关资源
        最近更新 更多