自版本 v0.26 起,R shiny 中使用的 DT 包的 background-color 已更改。这对你和我的问题来说是一样的吗?改变背景颜色不再起作用是一个错误吗?!
library(shiny)
testUI <- function(id) {
tagList(
DT::dataTableOutput(NS(id, "mytable")),
verbatimTextOutput(NS(id, "selected"))
)
}
testServer <- function(id) {
moduleServer(id, function(input,output,session,data) {
output$mytable <- DT::renderDataTable({
mtcars
}, selection = list(mode = "multiple", target = "row"))
output$selected <- renderPrint(
input$mytable_rows_selected # Caution: The prefix must match the id of my namespace
)
})
}
testApp <- function(install_version = c("v0.25", "v0.26"), change_background_color = FALSE) {
stopifnot(is.logical(change_background_color))
install_version <- match.arg(install_version)
if (install_version == "v0.25") {
remotes::install_github("rstudio/DT", ref = "v0.25", force = TRUE, upgrade = TRUE)
} else {
remotes::install_github("rstudio/DT", ref = "v0.26", force = TRUE, upgrade = TRUE)
}
ui <- fluidPage(
if (isTRUE(change_background_color)) {
tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: #FC8995 !important;}')) # red color
},
testUI("test")
)
server <- function(input, output, session) {
testServer("test")
}
shinyApp(ui, server)
}
DT 版本 v0.25 不带或带更改背景颜色:
testApp(install_version = "v0.25", change_background_color = FALSE) testApp(install_version = "v0.25", change_background_color = TRUE)
DT 版本 v0.26 不改变背景颜色和改变背景颜色:
testApp(install_version = "v0.26", change_background_color = FALSE) testApp(install_version = "v0.26", change_background_color = TRUE)
摘要:
background-color 真的从版本 v0.25 更改为 v0.26 吗?v0.26 版本中更改默认 background-color 不再起作用?Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
新版本中所选行的背景颜色不是使用
background-color属性设置的:它是使用 box-shadow 属性。 以下是更改所选行的背景颜色的方法: