How to add download button in shiny data table to download corresponding files

This is my sample code

library(shiny)
library(tidyverse)
library(DT)

ui <- fluidPage(
  DTOutput('table')
)
server <- function(input, output, session) {

  tibble(name = c("A", "B", "C"),
         file_key = c("sample_A.pdf", "sample_B.pdf", "sample_C.pdf")) -> df
  output$table <- DT::renderDT({
    DT::datatable(df)
  })

}
shinyApp(ui, server)

The respective files are stored in the home directory.

What I want to do is mutate the second column into a download button, which on click download the respective files. I found this post from stack overflow where they have used shinyInput and downloadhandler to achieve a similar outcome. But I cant figure out a way to make it work for me. If somebody could help me to understand this it'll be of great help. Thanks in advance.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.