Based on your comment:
Yes, data processing depends on user input. The user will upload some files and click the "Activation" button to begin processing. The download button is in a set of tabs.
Let's say the action button is called input$start_proc .
In server.R:
shinyServer(function(input, output, session) {
Then in ui.R you can write javascript for the custom message event handler.
Full example:
server.R
library(shiny) fakeDataProcessing <- function(duration) {
ui.R
library(shiny) shinyUI(fluidPage( singleton(tags$head(HTML( ' <script type="text/javascript"> $(document).ready(function() { // disable download at startup. data_file is the id of the downloadButton $("#data_file").attr("disabled", "true").attr("onclick", "return false;"); Shiny.addCustomMessageHandler("download_ready", function(message) { $("#data_file").removeAttr("disabled").removeAttr("onclick").html( "<i class=\\"fa fa-download\\"></i>Download (file size: " + message.fileSize + ")"); }); }) </script> ' ))), tabsetPanel( tabPanel('Data download example', actionButton("start_proc", h5("Click to start processing data")), hr(), downloadButton("data_file"), helpText("Download will be available once the processing is completed.") ) ) ))
In this example, the data processing is faked, waiting for 5 seconds. Then the download button will be ready. I also added some “fake” fileSize information to the fileSize to demonstrate how you can send additional information to the user.
Note that since Shiny implements actionButton as an <a> tag instead of a <button> and associates a click event with it. Therefore, in order to completely disable it, in addition to adding the disabled attribute, so that it seems to be disabled, you also need to override its click event by adding the onclick built-in attribute. Otherwise, the user may accidentally click the download button (apparently disabled) and start the download.
Xin yin
source share