chas
chas

Reputation: 1645

How to change color of R shiny datatable csv/excel/columnVisibility buttons using CSS

I have the below code which displays a datatable. Is it possible to change the color of the csv ,excel and columnVisibility buttons? I am not sure which CSS tags to change or modify to get the desired affect.

library(DT)
library(shiny)
library(shinydashboard)


ui <- dashboardPage(
  dashboardHeader(title = "Header"
                  ),
  dashboardSidebar( sidebarMenu(id = "tabs",
                                menuItem("Page1", tabName = "page1"))),
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "page1",
        
        tabBox(id="tabs",
               tabPanel("tab1",
                        column(12,
                               DT::dataTableOutput("table1")
                        ))
        )
      )
    )
  )
)


server <- function(input, output) {
  
  output$table1 <- DT::renderDataTable({
    datatable( data = mtcars,
               options = DToptions,
               extensions = 'Buttons',
               rownames = TRUE,
               selection = 'none'
    )
  })
  

  
  
}

shinyApp(ui, server)

Upvotes: 2

Views: 454

Answers (1)

TarJae
TarJae

Reputation: 78927

We could add a javascript/jquery to change the colors of the buttons in the callback:

  output$table1 <- DT::renderDataTable({
    datatable( data = mtcars,
               callback=JS('$("button.buttons-copy").css("background","red"); 
                    $("button.buttons-print").css("background","green"); 
                    return table;'),
               extensions = 'Buttons', options = list(
                 dom = 'Bfrtip',
                 buttons = c('copy', 'print')
               ),
               rownames = TRUE,
               selection = 'none'
    )
  })

enter image description here

Upvotes: 3

Related Questions