R/shiny_devmode.R

Defines functions get_shiny_devmode_option in_shiny_devmode

###
# These methods could be removed if shiny were able to be imported.
# * `shiny::in_devmode()`
# * `shiny::get_devmode_option()`
###


in_shiny_devmode <- function() {
  isTRUE(getOption("shiny.devmode", FALSE)) &&
    !identical(Sys.getenv("TESTTHAT"), "true")
}

#' @importFrom rlang missing_arg is_missing maybe_missing
get_shiny_devmode_option <- function(
  name,
  default = NULL,
  devmode_default = missing_arg(),
  devmode_message = missing_arg()
) {

  if (!in_shiny_devmode()) {
    # Dev Mode disabled, act like `getOption()`
    return(getOption(name, default = default))
  }

  # Dev Mode enabled, update the default value for `getOption()`
  getOption(name, default = {
    # Notify developer
    if (
      !is_missing(devmode_message) &&
      !is.null(devmode_message) &&
      getOption("shiny.devmode.verbose", TRUE)
    ) {
      devmode_message <- paste0("shiny devmode - ", devmode_message)
      rlang::inform(
        message = devmode_message,
        .frequency = "regularly",
        .frequency_id = devmode_message,
        .file = stderr()
      )
    }

    # Return Dev Mode default value `devmode_default`
    maybe_missing(devmode_default, default)
  })
}

Try the sass package in your browser

Any scripts or data that you put into this service are public.

sass documentation built on May 29, 2024, 11:51 a.m.