I'm using renderDataTable in my shiny app to create a datatable. I further use the "option" on the server side to add extension buttons such as copy, save, PDF, and CSV. Instead of buttons, I would like to show icons on the screen

Here is the code I have on the server side:

    output$table.summary<-renderDataTable({
      # some data to create a datatable ...  
      ,
      server = FALSE,
      extensions = c("Buttons"), 
      options = list(dom = 'Bfrtip',
                 buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),
                 scrollX = TRUE)
      )

The above code shows buttons on the screen for each of the actions listed under options (e.g., copy, csv, etc.); however, instead of buttons, I would like to use icons.

1 Answers

0
tosdanielle On

You can add icons to buttons like this:

library(DT)

ui <- basicPage(
  h2("DataTable"),
  DT::dataTableOutput("mytable")
)

server <- function(input, output) {
  output$mytable = DT::renderDataTable({
    mtcars}, 
    extensions = c("Buttons"),
    options = list(dom = 'Bfrtip',
                   buttons = list(list(extend = "excel", text = '<span class="glyphicon glyphicon-th"></span>'), 
                                  list(extend = "csv", text = '<span class="glyphicon glyphicon-download-alt"></span>')),
                   scrollX = TRUE)
  )
}

shinyApp(ui, server)

Which results in: Buttons icons