So I have a shiny app (https://github.com/tadeu95/BAGs) (http://tadeu-apps.shinyapps.io/bags) and I have several download buttons. Recently what has started to happen is that when I click the download button it activates two times and downloads the same file twice. I've tried on chrome, edge and mozzila and happens every time. I don't know what happened because I didn't touch the part of the code where the downloads are implemented.
This is a short reproducible example:
library(bold)
library(readr)
library(shiny)
library(shinyWidgets)
grades2<-function(groups){
taxon9<-bold_seqspec(taxon=groups, format = "tsv")
}
ui <- fluidPage(textInputAddon(inputId="taxa2",addon=icon("search"),width="500px",label=tags$h5(tags$strong("Enter the name of the taxonomic group or groups separated by commas, without spaces:")),placeholder="Example: Carnivora,Ursidae,Artiodactyla,Soricomorpha"),downloadBttn("downloadData_2",size="sm","Download"))
server <- function(input, output) {
taxaInput_2 <- reactive({grades2(unlist(strsplit(input$taxa2, ",")))})
output$downloadData_2 <- downloadHandler(
filename = function() {
paste(input$taxa2,sep_out=",", ".tsv")
},
content = function(file) {
shiny::withProgress(
message=paste0("Downloading and annotating library for ",input$taxa2,sep_out=","), detail='This may take several minutes',
value=10,
{
shiny::incProgress(10/10)
write_tsv(taxaInput_2(), file)
}
)
}
)
}
shinyApp(ui=ui,server=server)
One thing I've just discovered is that if instead of clicking the download button with the left button of the mouse, I click the right button and choose "open link in a new tab", it downloads the file correctly only once.
If anyone has any idea what the reason might be, I will be very thankful.
Hi, I' m just commenting to say that I have the exact same issue, on my shiny app running on Windows10, R 4.0. It started hapenning without change any change in the code either.
So I'd be very thankful too if anyone had an idea.
Thank you for your answer.
You're right I should have done that, here is the reprex :
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Download reprex"),
sidebarLayout(
sidebarPanel(),
mainPanel(
shinyWidgets::downloadBttn(
outputId = "download",
label = "Download data as .RData",
style = "bordered",
color = "default")
,
shiny::downloadButton(
outputId = "download",
label = "Download data as .RData")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
data <- data.frame(x1 = runif(100), r2 = runif(100))
output$download <- shiny::downloadHandler(
filename = function() {
paste("file_to_dl.RData")
},
content = function(file) {
save(data, file = file)
}
)
}
# Run the application
shinyApp(ui = ui, server = server)
It actually points out that the issue seems specific to shinyWidgets, as the shiny function triggers a normal behavior (one event only), whereas two are triggered with the shinyWidgets function.