daattali / shinycssloaders

⌛ Add loading animations to a Shiny output while it's recalculating
https://daattali.com/shiny/shinycssloaders-demo/
Other
399 stars 45 forks source link

Would like to provide ids for spinners #19

Closed ghost closed 4 years ago

ghost commented 6 years ago

Hello,

Is it possible for withSpinner to have an additional parameter called id with default value of NULL? And if it is NULL, it would get a random value from digest? There are cases where one would like to hide a widget and its spinner. Placing a specific id for the spinner did the trick for me.

withSpinner <- function(ui_element, type=getOption("spinner.type",default=1),color=getOption("spinner.color",default="#0275D8"),size=getOption("spinner.size",default=1),color.background=getOption("spinner.color.background"),custom.css=FALSE,proxy.height=if (grepl("height:\\s*\\d",ui_element)) NULL else "400px", id = NULL) {
  stopifnot(type %in% 1:8)

  if (grepl("rgb",color,fixed=TRUE)) {
    stop("Color should be given in hex format")
  }
  # each spinner will have a unique id, to allow seperate sizing - based on hashing the UI element code
  if (is.null(id)){
    id <- paste0("spinner-",digest::digest(ui_element))
  }
  ...
daattali commented 4 years ago

This has been added. It should be on CRAN soon