I want to create a button that downloads the filtered data of a dataTable, so I read these two posts and tried to do like them but I got an error and it didn't show the table rows. (please see the attachment)
R - Download Filtered Datatable and Download filtered data from renderDataTable() in Shiny
The error is: 'data' must be 2-dimensional (e.g. data frame or matrix) This is a part of my code:
#UI SECTION
downloadButton("download_filtered", "Download filtered dataset"), 
                     
                     verbatimTextOutput("filtered_row"),
                     DT::dataTableOutput("fancyTable"),
                     tags$hr(),
                     plotOutput("fancyPlot")
                              
#SERVER SECTION
server <- function(input, output) {
  output$fancyTable<- renderDataTable ({
my_data = data_filter()
 DT::datatable(my_data, extensions = "Buttons",
                          options = list(paging = TRUE,
                                         scrollX=TRUE,
                                         searching = TRUE,
                                         ordering = TRUE,
                                         dom = 'l<"sep">Bfrtip',
                                         buttons = c('copy', 'csv', 'excel', 'pdf'),
                                         pageLength=10,
                                         lengthMenu=c(10,20,50,100) )
                         )
              output$filtered_row <- renderPrint({
                input[["fancyTable_rows_all"]]
              })
            
            output$download_filtered <- downloadHandler(
                filename = "Filtered Data.csv",
                content = function(file){
                  write.csv(my_data[input[["fancyTable_rows_all"]], ],
                            file)
                }
              )
})
}
I would be happy if you have any suggestions. Thank you :)
 
    
