【问题标题】:R Shiny DataTable selected row color on specific tableR Shiny DataTable在特定表上选择了行颜色
【发布时间】:2018-10-13 08:26:51
【问题描述】:

我正在尝试对数据表中的行选择应用不同的颜色,如本文所述:R Shiny DataTable selected row color。 正如在下面的示例中所示,这适用于应用程序中的所有数据表。

library(shiny)
library(DT)

ui <- fluidPage(
  tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: black !important;}')),
  title = 'Select Table Rows',    
  fluidRow(
    column(6, DT::dataTableOutput('Table1')),
    column(6, DT::dataTableOutput('Table2'))
  )  
)

server <- function(input, output, session) {
  output$Table1 = DT::renderDataTable(cars, server = FALSE)
  mtcars2 = head(mtcars[, 1:8],10)
  output$Table2 = DT::renderDataTable(mtcars2, server = TRUE)
}

shinyApp(ui, server)

有没有办法明确指定哪个表会受此影响?

【问题讨论】:

    标签: r shiny datatables-1.10


    【解决方案1】:

    只需要在你的风格声明的开头添加#TableID。下面我将新的突出显示样式仅应用于Table1 -

    library(shiny)
    library(DT)
    
    ui <- fluidPage(
      tags$style(HTML('#Table1 table.dataTable tr.selected td, table.dataTable td.selected {background-color: black !important;}')),
      title = 'Select Table Rows',    
      fluidRow(
        column(6, DT::dataTableOutput('Table1')),
        column(6, DT::dataTableOutput('Table2'))
      )  
    )
    
    server <- function(input, output, session) {
      output$Table1 = DT::renderDataTable(cars, server = FALSE)
      mtcars2 = head(mtcars[, 1:8],10)
      output$Table2 = DT::renderDataTable(mtcars2, server = TRUE)
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 非常感谢这个 Shree。
    • 乐于助人。您可以使用此答案左上角的勾号将其标记为正确答案。谢谢!
    • 嘿!无论如何,在 bootstrap 4 中使用 bslib 是否可以做到这一点?在那种情况下这似乎不起作用@Shree
    猜你喜欢
    • 2017-12-11
    • 2017-06-13
    • 2015-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 2021-05-18
    • 2019-07-07
    • 1970-01-01
    相关资源
    最近更新 更多