You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Download handler downloads some "download.html" with the current page's HTML code while app is first loading #3606
I see this problem a lot when automating a Shiny app with Selenium, and have also come across it in manual app use. Apparently, it is not enough to wait for the download button to become clickable. Can I modify the Shiny app to prevent this issue? Is there any other state change that I can reliably wait for in Selenium to ensure that the download will succeed?
Reacted by Fernando Roa, Yi-Ju Tseng, samuelreuther, Krystian Igras, Matt Barry, Sebastian and Skyble
If you're seeing it while your app is first loading, there's not a fix (though we should totally fix it, it's so stupid and probably not that hard to fix). If you're seeing it in your app regardless of timing, it's likely your output$outputname <- downloadHandler is using an incorrect value for outputname.
I faced the same issue while having download button within initially hidden sidebar.
I suspect this might be connected to Shiny's optimization for rendering hidden outputs (display: none css property exactly).
You can exclude an output from this behavior by setting up suspendWhenHidden = FALSE output option (having this option set I've managed to solve the issue in my app).
If you're seeing it while your app is first loading, there's not a fix (though we should totally fix it, it's so stupid and probably not that hard to fix). If you're seeing it in your app regardless of timing, it's likely your output$outputname <- downloadHandler is using an incorrect value for outputname.
Hi @jcheng5 I am wondering if you can expand on this "when app is first loading, download can fail" thing? I have a feeling this could be the root cause of an issue I am having: #3748 (comment)
This post isn't related to the bug noted above, but I stumbled onto this thread while troubleshooting and thought someone else might too.
I'm posting this for anyone using the Rhino framework who is encountering the problem of downloadHandler outputting HTML vs CSV "regardless of timing" as Joe Chang mentioned above.
Something about Joe's below comment got me thinking there was something wrong with downloadButton.
output$outputname <- downloadHandler using an incorrect value for outputname
I tried outputOptions(output, "downloadData", suspendWhenHidden = FALSE) as mentioned by someone else above and the output message was an error stating the output ID couldn't be found, which was strange since the ID was defined in the downloadButton outputId arg.
Takeaway: if you're using the Rhino framework remember that outputIDs must be enclosed by ns() otherwise output$output_name won't be found. Once the downloadButton outputId arg was encapsulated with ns() downloadHandler worked as expected, it output a CSV.
outputOptions(output, "download_data", suspendWhenHidden = FALSE)
Error in .subset2(x, "impl")$outputOptions(name, ...) :
app-main-download_data is not in list of output objects
Could you please try outputOptions(output, "downloadData", suspendWhenHidden = FALSE)?
I've accidentally added space within the id ("downloadData ") in my previous answer, I suppose this is why you've got such errors.
@krystian8207 good catch, but I didn't use "downloadData " as the argument value. My outputID is "download_data". I've updated the reference to your original post to remove the space and the argument name in the code block. The error, in hindsight, was expected because when creating apps using the Rhino framework outputIDs [within a module] must be enclosed by ns(), which I omitted originally.
I don't know for certain what the issue is with your code. I'd recommend to add the error message to your post. However, at a glance I think one issue is the filename argument in downloadHandler should be a function. For example, as can be seen above:
@SaintRod I tried it with function but it does not work either :/ what do you mean by error message? I dont get any error, the code just downloads htm file
I'm not sure how you call the module, but in the above example commenting out data <- reactive({data()}) within a module helped to download the csv. Having this line uncommented I got:
Warning: Error in : C stack usage 7976452 is too close to the limit
3: runApp
2: print.shiny.appobj
1: <Anonymous>
and html file downloaded instead.
In fact you don't have to set outputOptions(output, "download_data", suspendWhenHidden = FALSE) in the example, csv still is downloaded correctly.
changed the title [-]Download handler downloads some "download.html" with the current page's HTML code[/-][+]Download handler downloads some "download.html" with the current page's HTML code while app is first loading[/+]on Mar 10, 2024
I updated the title of this issue to reflect the original post, which is related to app loading.
I was wondering if maybe the people who are discussing the unrelated issue of download issues after the app has finished loading (essentially, all comments after #3606 (comment)) could find a better place to discuss this. It's noise to all those watching this to see when the original issue is resolved. Thank you.
Reacted by Krystian Igras, Gabriel Ascui and Santiago
Hi everyone! I ran into the same issue when uploading my Shiny app on GitHub Page using shinylive. I had a downloadButton that worked great when running the app on my own local system, but could not download a table or a text file properly: instead of downloading a file "results.csv", it tried to download something like "download_results_csv.txt" or "download_results_csv.htm", where "download_results" would be the ID of the download button.
Activity
schloerke commentedon Mar 31, 2022
Thank you for the reprex. I am able to reproduce the bug using the example link.
demydd commentedon Jun 23, 2022
I have the same issue -> downloading of download.html instead of csv file.
tnguyenqh commentedon Oct 12, 2022
I am having the same issue as well. Has there been any fix? I am using shiny version 1.7.2
jcheng5 commentedon Oct 12, 2022
If you're seeing it while your app is first loading, there's not a fix (though we should totally fix it, it's so stupid and probably not that hard to fix). If you're seeing it in your app regardless of timing, it's likely your
output$outputname <- downloadHandleris using an incorrect value foroutputname.damienaymon commentedon Feb 9, 2023
Was there any update to the situation? Or is there any workaround that exists?
HassanMasoomi commentedon Feb 9, 2023
I couldn't find anything either...
erikvona commentedon Mar 7, 2023
I ran into this as well, really annoying.
I've posted a workaround here: https://gist.github.com/erikvona/96f0333704819ca242a9aed6cf07c07b but it's rather complex.
samsiljee commentedon Apr 14, 2023
I'm having the same problem too, although I am just learning shiny, so it could be an error I'm making myself
krystian8207 commentedon Jun 29, 2023
I faced the same issue while having download button within initially hidden sidebar.
I suspect this might be connected to Shiny's optimization for rendering hidden outputs (
display: nonecss property exactly).You can exclude an output from this behavior by setting up
suspendWhenHidden = FALSEoutput option (having this option set I've managed to solve the issue in my app).In case of the demo app, this would be:
gabrielascui commentedon Sep 12, 2023
Having the same issue with an app that used to work great before, has anything change to the shiny architecture that is producing this?
tylerlittlefield commentedon Oct 12, 2023
Hi @jcheng5 I am wondering if you can expand on this "when app is first loading, download can fail" thing? I have a feeling this could be the root cause of an issue I am having: #3748 (comment)
trafficonese commentedon Nov 23, 2023
This works with shiny_1.8.0 !
SaintRod commentedon Mar 1, 2024
Hi, all.
This post isn't related to the bug noted above, but I stumbled onto this thread while troubleshooting and thought someone else might too.
I'm posting this for anyone using the Rhino framework who is encountering the problem of downloadHandler outputting HTML vs CSV "regardless of timing" as Joe Chang mentioned above.
Something about Joe's below comment got me thinking there was something wrong with downloadButton.
I tried
outputOptions(output, "downloadData", suspendWhenHidden = FALSE)as mentioned by someone else above and the output message was an error stating the output ID couldn't be found, which was strange since the ID was defined in the downloadButton outputId arg.Takeaway: if you're using the Rhino framework remember that outputIDs must be enclosed by ns() otherwise output$output_name won't be found. Once the downloadButton outputId arg was encapsulated with ns() downloadHandler worked as expected, it output a CSV.
krystian8207 commentedon Mar 5, 2024
@SaintRod
Could you please try
outputOptions(output, "downloadData", suspendWhenHidden = FALSE)?I've accidentally added space within the id (
"downloadData ") in my previous answer, I suppose this is why you've got such errors.SaintRod commentedon Mar 5, 2024
@krystian8207 good catch, but I didn't use "downloadData " as the argument value. My outputID is "download_data". I've updated the reference to your original post to remove the space and the argument name in the code block. The error, in hindsight, was expected because when creating apps using the Rhino framework outputIDs [within a module] must be enclosed by ns(), which I omitted originally.
Arnold-Kakas commentedon Mar 9, 2024
@SaintRod Thank for your comment, I also use Rhino, but this didnt help.
Could you please compare my code to yours? maybe you will catch something
#' @export
ui <- function(id) {
ns <- NS(id)
downloadButton(
ns("download_data"),
label = "download",
icon = icon("download", verify_fa = FALSE)
)
}
#' @export
server <- function(id, data) {
moduleServer(id, function(input, output, session){
data <- reactive({data()})
})}
Thank you
SaintRod commentedon Mar 10, 2024
@Arnold-Kakas
I don't know for certain what the issue is with your code. I'd recommend to add the error message to your post. However, at a glance I think one issue is the
filenameargument indownloadHandlershould be a function. For example, as can be seen above:Arnold-Kakas commentedon Mar 10, 2024
@SaintRod I tried it with function but it does not work either :/ what do you mean by error message? I dont get any error, the code just downloads htm file
krystian8207 commentedon Mar 10, 2024
@Arnold-Kakas
Could you please try this example:
I'm not sure how you call the module, but in the above example commenting out
data <- reactive({data()})within a module helped to download the csv. Having this line uncommented I got:and html file downloaded instead.
In fact you don't have to set
outputOptions(output, "download_data", suspendWhenHidden = FALSE)in the example, csv still is downloaded correctly.[-]Download handler downloads some "download.html" with the current page's HTML code[/-][+]Download handler downloads some "download.html" with the current page's HTML code while app is first loading[/+]bersbersbers commentedon Mar 10, 2024
I updated the title of this issue to reflect the original post, which is related to app loading.
I was wondering if maybe the people who are discussing the unrelated issue of download issues after the app has finished loading (essentially, all comments after #3606 (comment)) could find a better place to discuss this. It's noise to all those watching this to see when the original issue is resolved. Thank you.
Close #3606: disable downloadLink()/downloadButton() until their href…
Disable `downloadLink()`/`downloadButton()` until their `href` is rea…
frees86 commentedon Feb 11, 2026
Hi everyone! I ran into the same issue when uploading my Shiny app on GitHub Page using shinylive. I had a downloadButton that worked great when running the app on my own local system, but could not download a table or a text file properly: instead of downloading a file "results.csv", it tried to download something like "download_results_csv.txt" or "download_results_csv.htm", where "download_results" would be the ID of the download button.
I struggled a lot but eventually ended up in the Posit page of downloadLink, where a very useful piece of code was introduced (https://shiny.posit.co/r/components/inputs/download-link/). So in the end, you would need to redefine the functions downloadLink or downloadButton in the following way if you encounter the same issue:
downloadLink <- function(...) {
tag <- shiny::downloadLink(...)
tag$attribs$download <- NULL
tag
}
downloadButton <- function(...) {
tag <- shiny::downloadButton(...)
tag$attribs$download <- NULL
tag
}
Now my app works great when running the app on a GitHub page using Chromium as the navigator!