R:突出显示数据表中的行的问题
R: Problem with highlighting a row in datatable
我最近一直在学习flexdashboard
制作仪表板。我正在尝试将特定行设置为 bold
,但如果我将 rownames
设置为 False
,它将无法正常工作。这是一个例子:
# This example sets the 3rd row to bold
df <- data.frame(
a = runif(3),
b = runif(3),
c = runif(3))
library(DT)
df %>%
datatable(rownames = T,
options = list(pageLength = 3,
searching = F,
lengthChange = F,
info = F,
paging = F,
ordering = F,
columnDefs = list(list(className = 'dt-center', targets = 0:3)))) %>%
formatStyle(
0,
target = "row",
fontWeight = styleEqual(3, "bold"))
如果rownames = F
,上面的例子将不起作用。我不想显示 rownames
。是什么原因,我该如何解决?
关闭行名称会删除您引用的索引以突出显示该行。所以我们需要创建自己的:
df$index <- seq(1,3)
然后,我们创建 datatable
,并在 columnDefs
中使用 list(visible = FALSE, targets = c(3))
隐藏 df$index
df %>%
datatable(rownames = F,
options = list(pageLength = 3,
searching = F,
lengthChange = F,
info = F,
paging = F,
columnDefs = list(list(className = 'dt-center', targets = 0:2), list(visible=FALSE, targets = c(3))))) %>%
formatStyle('index',
target = "row",
# this says 'style rows bold where index == 3'
fontWeight = styleEqual(3, "bold"))
我最近一直在学习flexdashboard
制作仪表板。我正在尝试将特定行设置为 bold
,但如果我将 rownames
设置为 False
,它将无法正常工作。这是一个例子:
# This example sets the 3rd row to bold
df <- data.frame(
a = runif(3),
b = runif(3),
c = runif(3))
library(DT)
df %>%
datatable(rownames = T,
options = list(pageLength = 3,
searching = F,
lengthChange = F,
info = F,
paging = F,
ordering = F,
columnDefs = list(list(className = 'dt-center', targets = 0:3)))) %>%
formatStyle(
0,
target = "row",
fontWeight = styleEqual(3, "bold"))
如果rownames = F
,上面的例子将不起作用。我不想显示 rownames
。是什么原因,我该如何解决?
关闭行名称会删除您引用的索引以突出显示该行。所以我们需要创建自己的:
df$index <- seq(1,3)
然后,我们创建 datatable
,并在 columnDefs
list(visible = FALSE, targets = c(3))
隐藏 df$index
df %>%
datatable(rownames = F,
options = list(pageLength = 3,
searching = F,
lengthChange = F,
info = F,
paging = F,
columnDefs = list(list(className = 'dt-center', targets = 0:2), list(visible=FALSE, targets = c(3))))) %>%
formatStyle('index',
target = "row",
# this says 'style rows bold where index == 3'
fontWeight = styleEqual(3, "bold"))