In a similar way to this question, it is possible to change the colour of selected rows in a datatable output using tags$style(HTML(...))
prior to the DTOutput()
function. E.g.,
library(shiny)
library(DT)
library(shinythemes)
ui <- fluidPage(theme = shinytheme("cyborg"),
tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: pink !important;}')),
mainPanel(DT::dataTableOutput('mytable'))
)
server <- function(input, output,session) {
output$mytable = DT::renderDataTable(
datatable(mtcars,
#style = "bootstrap" # Uncomment to see how the custom css above is overriden
)
)
}
runApp(list(ui = ui, server = server))
The code above renders a plainly formatted white table that looks out of place in the dark Cyborg bootstrap theme. It does, however, have the custom css applied, which means the selected rows become pink. By contrast, if you uncomment the style argument within datatable
the style of the datatable conforms exactly to the bootstrap theme, without the custom pink selected row style.
How do I apply the bootstrap theme to the datatable and override the style of selected rows?