R/skeleton.R

Defines functions skeletonOutput renderSkeleton

#' @export
renderSkeleton <- function(expr, env = parent.frame(), quoted = FALSE) {
  func <- shiny::exprToFunction(expr, env, quoted)
  function() {
    val <- func()
    val
  }
}

#' @export
skeletonOutput <- function(id, color = NULL, default = 100, container = shiny::span) {
  shiny::addResourcePath(
    prefix = "shuny",
    directoryPath = fs::path_package("shuny", "www")
  )
  libs <- shiny::singleton(
    tags$head(
      tags$script(src = "shuny/js/skeleton.js"),
      tags$link(rel = "stylesheet", href = "shuny/css/skeleton.css")
    )
  )

  style <- if (is.null(color)) NULL else paste0("--color: ", color)

  shiny::tagList(
    libs,
    container(
      id = id,
      class="skeleton",
      "data-skeleton" = default,
      style = style
    )
  )
}
shunsambongi/shuny documentation built on Aug. 19, 2022, 9:57 a.m.