R/tb_shiny.R

Defines functions tb_shiny

Documented in tb_shiny

#' Run Web-Based application
#'
#' Call Shiny to run \code{ctdesign} as a web-based application.
#'
#' @details
#'
#' A web browser will be brought up for users to access the GUI
#'
#'
#' @export
#'
tb_shiny <- function(appname = "shiny") {
    req.pkgs        <- c("shiny", "shinythemes", "DT",
                         "knitr", "rmarkdown", "pander",
                         "plotly");

    chk.uninstalled <- sapply(req.pkgs,
                              function(x) {
                                  !requireNamespace(x, quietly = TRUE)
                              })
    chk.inx         <- which(chk.uninstalled)

    if (0 < length(chk.inx)) {
        msg <- paste("For the GUI to work, please install ",
                     ifelse(1 < length(chk.inx), "packages ", "package "),
                     paste(req.pkgs[chk.inx], collapse = ", "),
                     " by \n install.packages(",
                     paste(paste("'",
                                 req.pkgs[chk.inx],
                                 "'",
                                 sep = ""), collapse = ", "),
                     ") \n  ",
                     sep = "");
        stop(msg, call. = FALSE);
    }

    appDir <- system.file(appname, package = "tburden")
    if (appDir == "") {
        stop("Could not find Shiny directory. Try re-installing `idem`.",
             call. = FALSE)
    }

    shiny::runApp(appDir, display.mode = "normal");
}
olssol/tburden documentation built on April 27, 2023, 12:14 p.m.