Change the color of the tablet buttons in the DT library in R

Instead of gray custom color change

For instance:

library(DT)
iris2 = head(iris, 20)
# only show the Copy and Print buttons
datatable(
  iris2,
  extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('copy', 'print')
  )
)

Gives us the following:

enter image description here

I would like to change the color of the Copy and Print buttons.

I went through https://datatables.net/extensions/buttons/examples/ but I can not find a solution.

+4
source share
1 answer

You can enable some javascript / jquery to change the colors of the buttons in the callback:

datatable(
        iris2,
        callback=JS('$("a.buttons-copy").css("background","red"); 
                    $("a.buttons-print").css("background","green"); 
                    return table;'),
        extensions = 'Buttons', options = list(
                dom = 'Bfrtip',
                buttons = c('copy', 'print')
        )
)
+3
source

All Articles