使用thisAnswer,我已经在SHILY中的数据表中添加了一列复选框.当复选框列不存在时,我可以用DT::formatStyle()
调整行高,但它不适用于具有复选框的表.下面是一个最小的例子:
library(shiny)
library(DT)
runApp(
list(ui = fluidPage(
column(width = 6,
dataTableOutput("cars_table")),
column(width = 6,
dataTableOutput("cars_table_check"))),
server = function(input, output, session) {
shinyInput <- function(FUN, id, num, ...) {
inputs <- character(num)
for (i in seq_len(num)) {
inputs[i] <- as.character(FUN(paste0(id, i), label = NULL, ...))
}
inputs
}
output$cars_table <- renderDataTable({
formatStyle(datatable(
mtcars,
selection = 'none', escape = F),
0, target = "row", lineHeight = "50%")
})
output$cars_table_check <- renderDataTable({
formatStyle(datatable(
cbind(Pick = shinyInput(checkboxInput, "srows_", nrow(mtcars), value = NULL, width = 1), mtcars),
options = list(drawCallback= JS('function(settings) {Shiny.bindAll(this.api().table().node());}')),
selection = 'none', escape = F),
0, target = "row", lineHeight = "50%")
})
})
)
以及输出: