R/openApp.R

Defines functions openApp

Documented in openApp

#' openApp
#'
#' Opens an example Shiny app into the RStudio editor.
#'
#' @param dir character: name of the app
#' @param ... further parameter given to [rstudioapi::navigateToFile()]
#'
#' @return invisibly the result of `navigateToFile`
#' @importFrom rstudioapi navigateToFile
#' @export
#'
#' @examples
#' # Example requires the use of a `shiny` app (See Vignette)
#' # Runs only in RStudio and in an interactive session
#' if (interactive()) {
#'   # Runs the minimal example app file in the editor
#'   openApp("mini")
#' }
#'
#' \dontrun{
#' # If the directory doesn't match, an error will appear
#' openApp("nonexistent")
#' }
openApp <- function(dir = "mini", ...) {
  appdir <- system.file('examples-shiny', package = "shinyDTC")
  appdir <- list.dirs(appdir, recursive = FALSE)
  i <- pmatch(dir, basename(appdir), nomatch = 0L)
  if (i == 0L) {
    stop(sprintf("'dir' should be one of %s", paste(basename(appdir), collapse = ", ")))
  }
  invisible(navigateToFile(paste0(appdir[i], '/app.R')))
}

Try the shinyDTC package in your browser

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

shinyDTC documentation built on June 8, 2025, 9:32 p.m.