I have found a (not so pretty) solution (but it works), so I share it :
1. First, in the UI part I create an invisible download link (I set
label ="" to get it invisible => it allows to declare a downloadLink but not to see it):
downloadLink("downloadData",label="")2. I also declare (in the UI part) this javascript code (inspired by
this) :
tags$head(tags$script(HTML('
Shiny.addCustomMessageHandler("jsCode",
function(message) {
eval(message.value);
});'
)))3. In the server part I create thise observer (partially inspired by
this)
observeEvent(input$my_own_trigger, {
output$downloadData<<-downloadHandler(filename = x$Nom,content = function(file)file.copy(file0,file) )
jsinject <- "setTimeout(function(){window.open($('#downloadData').attr('href'))}, 100);"
session$sendCustomMessage(type = 'jsCode', list(value = jsinject))
})So now I can produce a download in the client side with any trigger (
input$my_own_trigger)