Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

input_task_button - downloadButton equivalent #1138

Open
jack-davison opened this issue Nov 22, 2024 · 2 comments
Open

input_task_button - downloadButton equivalent #1138

jack-davison opened this issue Nov 22, 2024 · 2 comments

Comments

@jack-davison
Copy link

Hello,

Big fan of input_task_button()

Sometimes a downloadButton may take a little while to prepare its contents (e.g., if you're downloading a shapefile, you may need to write it to a temp directory, zip that file, and then download that zipped file) and I wouldn't want a user to hammer the download button over and over.

So, my question is - is there an equivalent for shiny::downloadButton() on the horizon?

Or is there already a way to link up input_task_button() to a download manager?

Cheers!

@gadenbuie
Copy link
Member

This would be a good fit for the "v2 API" I've proposed in #1077. I think it might be relatively easy to implement, but for backwards compatibility reasons it'd be much easier to do in a new function

@datatenk
Copy link

datatenk commented Mar 7, 2025

In the context of using input_task_button with ExtendedTask, I used the following workaround:

  1. In the UI, create an invisible shiny::downloadButton (this would be the trigger for the download action after all the ExtendedTask work has completed), for the example assign it the id of download_trigger. To make it invisible, you have the option of using the BS5 utility class for visibility, or wrap the shiny::downloadButton in a div with zero height.
  2. In the UI, create a (visible) input_task_button, this is what the user would click on.
  3. In the Server, create your ExtendedTask object ($new()), and bind to your input_task_button.
  4. In the Server, in the observeEvent handler for the input_task_button, $invoke() on the ExtendedTask object created in step 3.
  5. In the Server, create an observeEvent for the $status() of the ExtendedTask object created in step 3.
    If the $success() of your ExtendedTask object TRUE, then "programmatically click" on the invisible shiny::downloadButton created in step 1 by calling shinyjs::click('download_trigger').

Note that in the downloadHandler for your invisible shiny::downloadButton button, you pass the $result() of your ExtendedTask object as the data for download.

That's it!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants