2016-07-23 45 views
0

我在下面的示例2.5中:https://rstudio.github.io/DT/以閃亮的方式創建自定義數據表容器。這個例子似乎可以自行工作。但是當我嘗試在一個閃亮的應用程序中運行它時,Sepal和Petal標題不居中。請幫忙。謝謝。Shiny中的中心自定義數據表容器列標題

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) 

    }) 
} 
)) 

回答

1

在你的用戶界面,添加此標籤:

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

前:

rowspan=2 

補充一點:

class = 'dt-center'