自版本以來, R 中使用的包的版本已v0.26更改。這對你和我的問題是否一樣,改變背景顏色不再起作用是一個錯誤嗎?!background-colorDTshiny
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? - 為什么更改
background-color版本中的默認值v0.26不再起作用?
uj5u.com熱心網友回復:
新版本中所選行的背景顏色不是用background-color屬性設定的:它是用box-shadow屬性設定的。以下是如何更改所選行的背景顏色:
library(shiny)
library(DT)
css <- "
table.dataTable tr.selected td, table.dataTable td.selected {
box-shadow: inset 0 0 0 9999px #FC8995 !important;
}
"
ui <- fluidPage(
tags$style(HTML(css)),
br(),
DTOutput("dtable")
)
server <- function(input, output, session) {
output[["dtable"]] <- renderDT({
datatable(iris)
})
}
shinyApp(ui, server)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/524546.html
標籤:cssr闪亮的dt
下一篇:透視資料框以獲取基線分數作為列
