download table with search bar

26 views
Skip to first unread message

Samantha Alger

unread,
Aug 7, 2018, 10:24:03 AM8/7/18
to shinyapps.io Users
Hello,

I've created a table with a search bar that allows me to query the data and it shows only the rows that meet a criteria. I've also created a download button that will allow me to download the table as a csv file. Right now, I can only download the entire data table. Is there a way to make the output of the download button show only the records that I've queried using the search bar?  Below are the sections from my server and ui: 


server:

    # create an output table of this dataframe (Full table on tab)
    output$table <- DT::renderDataTable({
      DT::datatable(SSdat[[1]])
      # search box:
      output$table <- DT::renderDataTable(
        DT::datatable(SSdat[[1]], options = list(searching = TRUE))
      )
    })
    # Downloadable csv of selected dataset ----
    output$downloadData <- downloadHandler(
      filename = function() {
        paste("ApiaryDataSubset",rad,"miles", ".csv", sep = "")
      },
      content = function(file) {
        write.csv(SSdat[[1]], file)
      }
    )


ui:
                 # creating an ouput for the table
                 tabPanel("Table",
                          DT::dataTableOutput("table"),
                          # Button
                          downloadButton("downloadData", "Download")
                 ),
Reply all
Reply to author
Forward
0 new messages