可能的問題:將'background-color”與'DT”一起使用時出現意外結果
P粉983021177
P粉983021177 2024-03-30 09:30:22
0
1
405

自版本 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 不再起作用?

P粉983021177
P粉983021177

全部回覆(1)
P粉299174094

新版本中所選行的背景顏色不是使用 background-color 屬性設定的:它是使用 box-shadow 屬性。 以下是更改所選行的背景顏色的方法:

library(shiny)
library(DT)

css 
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!