Open dracodoc opened 6 years ago
This sounds like an issue with the Mac version of the IDE (I've tested on 1.1.374). On Windows, the problem doesn't seem to happen.
@jmcphers, @kevinushey, is there an existing issue for this for the IDE?
Here's a reproducible example:
library(shiny)
shinyApp(
fluidPage(
downloadButton("downloadData", "Download")
),
function(input, output) {
output$downloadData <- downloadHandler(
filename = "mtcars.csv",
content = function(file) {
cat("content function started\n")
write.csv(mtcars, file, row.names = FALSE)
cat("content function ended\n")
}
)
}
)
It looks like the content function gets triggered twice: once, when the Download button is clicked (I believe this is expected), and then a second time after the download is complete (unexpected).
It seems like this only occurs if you're interacting with the Shiny application from the Viewer pane; it doesn't occur if the application is opened in a separate browser window.
I also notice that RStudio opens a separate RStudio window, and the download appears to be initiated from there (?). If you cancel the download, the contents of mtcars
show up in that window (but the content function is only triggered once).
I'll file this on the IDE side and we'll see if we can figure out what's going on. FWIW the same issue reproduces with RStudio v1.0 so I suspect this has been a long-running issue.
It looks like we didn't have an existing issue for this on the IDE side, so I've filed it there. We'll loop back in after we've figured out what's going on. Thanks for reporting!
Yes it's limited to RStudio Mac builtin browser (an older version of safari or webkit?).
I'm not sure which execution is expected though. The 1st time is before confirming a file name. If it's intended to
then this is correct. Otherwise if it's intended to
then the 1st execution is redundant.
RStudio windows seemed cannot take the file
parameter value, the default file name is the output slot name instead. Is this a known limitation?
When running a Shiny app in RStudio Mac, the
content
function indownloadhandler
will execute twice.content
function run once.content
function run again.In my app I dynamically generate some files and pack them into zip when user clicked a download button. This behavior caused the files to be generated twice.
This only apply to the RStudio builtin shiny browser(safari). The Mac Safari and Chrome don't have this problem.
There are some other random bugs, when the download process will actually start a new app instance (in Mac Safari) or download a html which is just app html (in Mac Chrome). That was not easily reproducible but should be relate to this bug.
To test the behavior, just add these two line in the download example: