render output functions inside the fucnctions

I have a download handler (say 10 times) that needs to be put in shiny as shown below. So instead of writing it 10 times, I have written a function so that after passing 3 parameters, the render functions should get executed

Button 1

output$downloadData_sec1 <- downloadHandler(
  filename = function() {
    paste(str_replace("title",pattern = " ", "_"), Sys.Date(), ".csv", sep="_")
  },
  content = function(file) {
    write.csv(display_data$asd, file)
  }
)

Button 2

output$downloadData_sec2 <- downloadHandler(
  filename = function() {
    paste(str_replace("title2",pattern = " ", "_"), Sys.Date(), ".csv", sep="_")
  },
  content = function(file) {
    write.csv(display_data$asd2, file)
  }
)

function (inside server function)

download_function <- function (id, title, data){
output[["id"]] <- downloadHandler(
  filename = function() {
    paste(str_replace(title,pattern = " ", "_"), Sys.Date(), ".csv", sep="_")
  },
  content = function(file) {
    write.csv(display_data[["data"]], file)
  }
)
}

But looks like there is some error here . I get output not defined Can anyone help me here?

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.