Skip to content

input_task_button - downloadButton equivalent #1138

Open

Description

@jack-davison

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!

Activity

  1. gadenbuie commented on Nov 22, 2024

    @gadenbuie
    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

  2. datatenk commented on Mar 7, 2025

    @datatenk

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions