downloadButton Disable "target='_blank" tag?

Hi,
In my Shiny Dashboard App, the user has the option of processing and downloading a PDF report. (The report is written for Sweave and the processing uses knitr and text2pdf.) This functionalist is triggered with a downloadButton and a downloadHanfler. When the button is clicked, Chrome opens up a new browser tab for the duration of the processing.

I have read on Stack Overflow and elsewhere that this behavior is caused by an inclusion of a "target='_blank'" tag in the HTML code associated with the button. Is there a way to disable this tag?

TIA
AB

One way to accomplish what you want is to edit the downloadButton function to create your desired effect:

# Below is the code for downloadButton
function (outputId, label = "Download", class = NULL, ...) 
{
    aTag <-
        tags$a(
            id = outputId,
            class = paste("btn btn-default shiny-download-link",
                          class),
            href = "",
            target = "_blank", # This is the only part you'd need to change
            download = NA,
            icon("download"),
            label,
            ...
        )
}

# You can assign the above function to another object and edit the 'target' argument
downloadButtonEdit <- function (outputId, label = "Download", class = NULL, ...) 
{
    aTag <-
        tags$a(
            id = outputId,
            class = paste("btn btn-default shiny-download-link",
                          class),
            href = "",
            target = NA, # NA here instead of _blank
            download = NA,
            icon("download"),
            label,
            ...
        )
}

Then just replace dowloadButton in your code with the downloadButtonEdit (or whatever you name it)

1 Like