您可以使用 CSS 来执行此操作。所选行的颜色设置为table.dataTable tbody tr.selected { background-color: #B0BED9;}
in jquery.min.dataTables.css
.
这是一个基于您的代码的最小示例,说明如何使用tags$style
:
library(shinydashboard)
header <- dashboardHeader(title = 'title')
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
)
)
body <- dashboardBody(
tags$head(tags$style(HTML("#table1 tr.selected, #table2 tr.selected {background-color:red}"))),
fluidRow(
column(width = 6,
box(
title = 'box', width = NULL, status = 'primary',
DT::dataTableOutput('table1')
),
box(
title = 'box', width = NULL, status = 'primary',
DT::dataTableOutput('table2')
)
)
)
)
ui<-dashboardPage(header, sidebar, body)
server = function(input, output) {
output$table1 = DT::renderDataTable(
iris, options = list(lengthChange = FALSE)
)
output$table2 = DT::renderDataTable(
iris, options = list(lengthChange = FALSE)
)
}
shinyApp(ui,server)
我添加了表 id (#table1 tr.selected, #table2 tr.selected
)以便此选择器比默认选择器具有更大的权重并覆盖它,有关此的更多信息here https://stackoverflow.com/questions/20721248/best-way-to-override-bootstrap-css.