Hello. I have a Shiny app with a download button. Everything works fine, but if I add a reactive object to the downloadHandler (example code below), the button icon disappears and the button collapses (no text visible) upon page load. I suspect it has something to do with the reactive object "result()" I have in the download handler but I am not sure how to work around this because the file name and content is only set after a button click which fires eventReactive and creates "result()".
output$download_gt_table <- downloadHandler(
# NOTE: result() is a list object created in a eventReactive() function. It has properties: down_file and
#tmp_file)
filename = result()$down_file,
content = function(file) {
tmp_file <- result()$tmp_file
file.copy(tmp_file, file)
}
)
Hi @fritzjooste. To assist in troubleshooting, can you please provide all of the shiny app code, or a smaller app that demonstrates the issue you’re seeing?
Hi @scottyd22 - many thanks for helping me with this. Below is a reduced example of my app which reproduces the error. When I run this app, the download button briefly flashes with the icon visible and the size correct, but then the icon disappears and the button collapses to a thin sliver.
Thank you for providing the example! It looks like the issue stems from the eventReactive not being created until the button is clicked. Thus, nothing initially exists for result(), which is being passed to downloadHandler(). This can be corrected by adding ignoreNULL = F, as shown below.
result <- eventReactive(input$btn_go, {
result = list(down_file = "none", tmp_file = "none")
return(result)
}, ignoreNULL = F)