可能的问题:将'background-color”与'DT”一起使用时出现意外结果
P粉983021177
P粉983021177 2024-03-30 09:30:22
0
1
399

自版本 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学习者快速成长!