flexdashboard icon indicating copy to clipboard operation
flexdashboard copied to clipboard

Bug in `downloadButton` with `downloadHandler` explicitly assigned to output slot

Open landroni opened this issue 6 years ago • 2 comments

This report is for two separate, but related issues.

In flexdashboard the downloadButton() doesn't seem to behave as documented. There are two issues that I could identify:

  1. When used as per the documentation (?downloadButton), with the downloadHandler() explicitly assigned to an output slot, the download button doesn't render at all.
  2. When defining the downloadHandler() anonymously, the download button will render, but it's label will be hardcoded to Download, as it seems to ignore custom labels.

None of these issues seem to affect the Download Link, which both renders as expected and takes into account a custom label.

Here's a minimum reproducible example.

---
title: "Bug with download button"
output:
    flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

Column {.sidebar}
---

```{r}
data("mtcars")

## download link works as documented
tags$div("Link displayed as expected:")
downloadLink(outputId = "dwnLink", label = "Download Link")
output$dwnLink <- downloadHandler(
    filename = function() {"mtcars.csv"},
    content = function(file){
        write.csv(mtcars, file)
    }
)

tags$hr()


## does NOT work as documented:
## download button doesn't render at all
tags$div("Button NOT displayed:")
downloadButton(outputId = "dwnButton", label = "Download Button")
output$dwnButton <- downloadHandler(
    filename = function() {"mtcars.csv"},
    content = function(file) {
        write.csv(mtcars, file)
    }
)

tags$hr()


## undocumented behavior
## downloadHandler() used anonymously, i.e. NOT explicitly assigned to an output slot
## button renders, BUT button label doesn't change
tags$div("Button displayed, but custom label ignored:")
downloadButton(outputId = "dwnButton2", label = "Download Button (LABEL IGNORED)")
downloadHandler(
    filename = function() {"mtcars.csv"},
    content = function(file) {
        write.csv(mtcars, file)
    }
)

tags$hr()
```

And the corresponding screenshot: screenshot_2018-09-10_21-09-26


> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18          digest_0.6.15         rprojroot_1.3-2       mime_0.5             
 [5] R6_2.2.2              xtable_1.8-2          jsonlite_1.5          backports_1.1.2      
 [9] magrittr_1.5          evaluate_0.10.1       stringi_1.1.6         DT_0.4               
[13] rmarkdown_1.10        flexdashboard_0.5.1.1 tools_3.4.4           stringr_1.2.0        
[17] htmlwidgets_1.0       shiny_1.0.5           httpuv_1.3.5          yaml_2.1.16          
[21] compiler_3.4.4        htmltools_0.3.6       knitr_1.19           

landroni avatar Sep 11 '18 04:09 landroni

I suspect this is related to the issue reported in #141.

landroni avatar Sep 11 '18 04:09 landroni

what is the status here? I still have this error with latest flexdashboard

LeoWelter avatar Mar 23 '20 12:03 LeoWelter