DT: An R interface to the DataTables library

Rstudio

datatable(iris 
          , options = list(
            # 是否要有排序功能
            ordering = FALSE
            # 寬度自動對齊
            , autoWidth = TRUE
            # 調整所有欄位寬度
            , columnDefs = list(list(width = '200px', targets = "_all"))
            # 調整指定欄位寬度
            , columnDefs = list(list(width = '50px', targets = 5))
            # 是否要顯示分頁 FALSE 會在網頁顯示所有資料,表格會被拉長
            , paging = TRUE
            # 頁籤的最大列數
            , pageLength = 5
            # 是否要搜尋框
            , searching = FALSE
          )
          # 移除列名稱
          , rownames= FALSE
          ) %>%
          formatStyle(
            # 指定欄位(可寫名稱或索引位置)
            columns = 'Sepal.Length'
            # columns = 2,
            # 文字顏色
            , color = 'red'
            # 背景顏色
            , backgroundColor = 'orange' 
            # 粗體
            , fontWeight = 'bold'
          )

columnDefs

Shiny

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(DTOutput('tbl')),
  server = function(input, output) {
    output$tbl = renderDT(
      iris
      # options 只能選一邊使用
      # iris, options = list(lengthChange = FALSE)
      # 移除列名稱
      , rownames = F
      # 列選擇變單選
      , selection = 'single'
      # 表格中的內容不換行
      , class = "nowrap row-border"
      , options = list(
        # columnDefs = list(
        #      list(targets=c(1,23)-1, searchable=F)
        #     ,list(targets=c(1,23)-1, visible=F)
        #     ,list(targets=c(3:22)-1, className='dt-center')
        # )
        scrollX = TRUE
        , scrollY = "200px"
        # 是否要顯示分頁 FALSE 會在網頁顯示所有資料,表格會被拉長
        , bPaginate = FALSE
        # 針對搜尋條件作 Height light
        , searchHighlight = TRUE
        # 頁籤的最大列數
        , pageLength = 5
    )
    )
  }
)