全てのデータを表示する場合

DT::datatable(mtcars)

 

表示のアレンジ例

縦罫線を追加してコンパクトに

DT::datatable(mtcars, class = "cell-border stripe compact")

 

キャプションを追加

DT::datatable(mtcars, class = "cell-border stripe compact",
              caption = "Table: Motor Trend Car Road Tests Data")

 

表示行数を変更

DT::datatable(mtcars, class = "cell-border stripe compact",
              caption = "Table: Motor Trend Car Road Tests Data",
              options = list(pageLength = 6))

 

フィルタを追加

DT::datatable(mtcars, class = "cell-border stripe compact",
              caption = "Table: Motor Trend Car Road Tests Data",
              options = list(pageLength = 6), filter = "top")

 

高度なアレンジ例

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,
              class = "stripe compact")

 

戻る