Adding Button to my Data Table


#1

Hello R people! Please I am trying to add buttons like 'pdf','csv' to my data table. I believe I have written the code well, but I keep getting the following error message each time I run the app:

Listening on http://127.0.0.1:5903
Warning: Error in FUN: The extension Button does not exist
Stack trace (innermost first):
    86: FUN
    85: lapply
    84: unlist
    83: datatable
    82: widgetFunc
    81: func
    80: origRenderFunc
    79: renderFunc
    78: origRenderFunc
    77: output$Tab
     1: runApp

Is there some thing I am missing? Here is the server code I have written:

output$Tab<-renderDataTable(
        
        data.frame(
        "People"=people,
        "Industries"=industries,
        "Schools"=schools,
        "Hospitals"=hospitals),
          extensions='Button',options=list(dom='Bfrtip',buttons=list(
            'copy','pdf','csv','excel','print'
          ))

I have also tried the datatable() function in place of the renderDatatable() code, but my app will not load when I try to run it, and I get the following error message:

Listening on http://127.0.0.1:5903
Warning: Error in FUN: The extension Button does not exist
Stack trace (innermost first):
    47: FUN
    46: lapply
    45: unlist
    44: datatable
    43: server [C:\Users\Idiaye\Documents\Plots/app.R#178]
     1: runApp
Error in FUN(X[[i]], ...) : The extension Button does not exist

Please, I will really appreciate your help, I beg!


#2

Try this -

library("shiny")
library("DT")

data = mtcars
server <- shinyServer(
  function(input, output, session) {
output$table <- DT::renderDataTable({
datatable({data}, filter="top", selection="multiple", 
                                  extensions = 'Buttons',
                                  options = list(pageLength = 10, 
                                                autoWidth = TRUE,
                                                dom = 'Bfrtip',
                                                buttons = c('copy', 'csv', 'pdf')
))
})

})


ui = shinyUI(fluidPage(
    DT::dataTableOutput("table")
))

shinyApp(ui, server)

#3

Hi, thanks for your suggestion, but it still did not work. I am wondering whether it has anything to do with the version of my studio, which is 3.3.0. Do I need to upgrade to 3.3.1?