shiny
shiny copied to clipboard
downloadButton doesn't render in rmarkdown
This is easily fixable with a new function
downloadButtonRmd <- function (outputId, label = "Download", class = NULL, ...) {
tags$a(id = outputId, class = paste("btn btn-default shiny-download-link",
class), href = "", target = "_blank", download = NA,
icon("download"), label, ...)
}
Have you tried surrounding your call to shiny::downloadButton()
with parentheses? The toy example below does render for me, but may be too trivial a use case.
```{r results="asis"} (shiny::downloadButton("hello", "world")) ```
Looking over the source code for downloadButton()
, I am curious why the generated tag is not explicitly returned.
https://github.com/rstudio/shiny/blob/master/R/bootstrap.R#L1461-L1471
The git blame for downloadButton
suggests the function has not been touched for years. None of the related commits suggest the current behaviour was required to workaround a bug at the time.
Looks like the aTag
assignment versus explicit return first appeared here, https://github.com/rstudio/shiny/commit/284e814d2a190b5d1950b3f09148b4b8904f286e.
It works with parentheses for me as well, so that's an easy workaround, thanks. Like you, I had a look at the function body and saw that it was returning invisibly, so I just re-wrote a version which returns visibly. I guess I don't know enough about shiny to understand how it manages to render in shiny, even without parentheses.
just to add a comment to this issue, I have just created a package that implements a download button in RMarkdown without the need for shiny: https://fmmattioni.github.io/downloadthis/
Thanks @fmmattioni this is very usefull !
@fmmattioni Your package is very good. Congratulations. Do you have any example of application of your package. How to implement in RMarkdown? Does it have to be inside the chunks? Thanks
Just reporting this is still happening on my system (and it took me a while to figure it out why it didn't appear) :
Session Info
session_info()
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.2.2 (2022-10-31)
os Ubuntu 22.04.3 LTS
system x86_64, linux-gnu
ui RStudio
language en_US:en
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Madrid
date 2023-09-25
rstudio 2023.06.1+524 Mountain Hydrangea (desktop)
pandoc 2.9.2.1 @ /usr/bin/pandoc
─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
cachem 1.0.8 2023-05-01 [1] RSPM (R 4.2.0)
callr 3.7.3 2022-11-02 [1] CRAN (R 4.2.2)
cli 3.6.1 2023-03-23 [1] RSPM (R 4.2.0)
crayon 1.5.2 2022-09-29 [1] CRAN (R 4.2.2)
devtools * 2.4.5 2022-10-11 [1] RSPM (R 4.2.0)
digest 0.6.33 2023-07-07 [1] RSPM (R 4.2.0)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.2)
fastmap 1.1.1 2023-02-24 [1] RSPM (R 4.2.0)
fs 1.6.3 2023-07-20 [1] CRAN (R 4.2.2)
glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.2)
htmltools 0.5.6 2023-08-10 [1] RSPM (R 4.2.0)
htmlwidgets 1.6.2 2023-03-17 [1] RSPM (R 4.2.0)
httpuv 1.6.11 2023-05-11 [1] RSPM (R 4.2.0)
later 1.3.1 2023-05-02 [1] RSPM (R 4.2.0)
lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.2)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.2)
memoise 2.0.1 2021-11-26 [1] CRAN (R 4.2.2)
mime 0.12 2021-09-28 [1] CRAN (R 4.2.2)
miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.2.2)
pkgbuild 1.4.2 2023-06-26 [1] RSPM (R 4.2.0)
pkgload 1.3.2.1 2023-07-08 [1] RSPM (R 4.2.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.2.2)
processx 3.8.2 2023-06-30 [1] RSPM (R 4.2.0)
profvis 0.3.8 2023-05-02 [1] RSPM (R 4.2.0)
promises 1.2.1 2023-08-10 [1] RSPM (R 4.2.0)
ps 1.7.5 2023-04-18 [1] RSPM (R 4.2.0)
purrr 1.0.2 2023-08-10 [1] RSPM (R 4.2.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.2)
Rcpp 1.0.11 2023-07-06 [1] RSPM (R 4.2.0)
remotes 2.4.2 2021-11-30 [1] CRAN (R 4.2.2)
rlang 1.1.1 2023-04-28 [1] RSPM (R 4.2.0)
rstudioapi 0.15.0 2023-07-07 [1] RSPM (R 4.2.0)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.2)
shiny 1.7.5 2023-08-12 [1] RSPM (R 4.2.0)
stringi 1.7.12 2023-01-11 [1] CRAN (R 4.2.2)
stringr 1.5.0 2022-12-02 [1] CRAN (R 4.2.2)
urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.2.2)
usethis * 2.2.1 2023-06-23 [1] RSPM (R 4.2.0)
vctrs 0.6.3 2023-06-14 [1] RSPM (R 4.2.0)
xtable 1.8-4 2019-04-21 [1] CRAN (R 4.2.2)
[1] /home/[email protected]/R/x86_64-pc-linux-gnu-library/4.2
[2] /opt/R/4.2.2/lib/R/library
────────────────────────────────────────────────────────────────────────────────────────────────────────
Maybe it could be documented in ?downloadButton. Thanks for providing the workaround https://github.com/rstudio/shiny/issues/2392#issuecomment-484097398