簡體   English   中英

R Shiny DataTable在特定表上選擇行顏色

[英]R Shiny DataTable selected row color on specific table

我正在嘗試將不同的顏色應用於本表中提到的數據表中的行選擇: R Shiny DataTable選擇了行顏色 在下面的示例中,這似乎適用於應用程序內的所有數據表。

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)

有沒有一種方法可以明確指定受此影響的表?

只需在樣式聲明的#TableID添加#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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM