如何在数据表中设置粗体行?

问题描述 投票:0回答:1

我正在使用 datatable() 函数在 HTML 输出中可视化数据框,现在我想在 bold

中设置第 4 行和第 8 行
df <- data.frame (origin = c("A","B","C","D","E","F","G","H","I","J"),
              Percentage = c(23,16,32,71,3,60,15,21,44,60),
              rate = c(10,12,20,200,-25,12,13,90,-105,23),
              change = c(10,12,-5,12,6,8,0.5,-2,5,-2))

library(DT)

# no clear buttons
datatable(df, options = list(autoWidth = TRUE, initComplete = JS("
                        function(settings, json) {
                          $(this.api().table().header()).css({
                          'font-size': '12px',
                          });
                        }
                    ")), filter = list(
  position = 'top', clear = FALSE
))%>%
  formatStyle(columns = colnames(.$x$data), `font-size` = "11px")

enter image description here

r dt
1个回答
3
投票

我们可以使用:

library(DT)
datatable(df, options = list(autoWidth = TRUE, initComplete = JS("
                        function(settings, json) {
                          $(this.api().table().header()).css({
                          'font-size': '12px',
                          });
                        }
                    ")), filter = list(
                      position = 'top', clear = FALSE ))%>%
 
  formatStyle(
    0,
    target = "row",
    fontWeight = styleEqual(c(4, 8), "bold"),
    `font-size`="11px"
  )

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.