Problème possible : résultats inattendus lors de l'utilisation de "background-color" avec "DT"
P粉983021177
P粉983021177 2024-03-30 09:30:22
0
1
397

Modifié depuis la version v0.26 起,R shiny 中使用的 DT 包的 background-color. Est-ce le même problème pour vous et moi ? Est-ce un bug qui fait que changer la couleur de fond ne fonctionne plus ? !

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 version v0.25 sans ou avec changement de couleur de fond :

testApp(install_version = "v0.25", change_background_color = FALSE)
testApp(install_version = "v0.25", change_background_color = TRUE)

DT version v0.26 sans changer la couleur de fond et changer la couleur de fond :

testApp(install_version = "v0.26", change_background_color = FALSE)
testApp(install_version = "v0.26", change_background_color = TRUE)

Résumé :

  • Par défaut background-color 真的从版本 v0.25 更改为 v0.26 pour les lignes sélectionnées ?
  • Pourquoi
  • ne fonctionne plus en v0.26 版本中更改默认 background-color ?

P粉983021177
P粉983021177

répondre à tous(1)
P粉299174094

La couleur d'arrière-plan de la ligne sélectionnée dans la nouvelle version n'est pas définie à l'aide de l'attribut background-color : elle est définie à l'aide de l'attribut box-shadow. Voici comment changer la couleur d'arrière-plan d'une ligne sélectionnée :

library(shiny)
library(DT)

css 
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!