aboutsummaryrefslogtreecommitdiff
path: root/R/app.R
blob: 23e32ab8674be017cf43500d9e8ed941172c6714 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' Launch the Rnaught Web Application
#'
#' @importFrom utils install.packages
#'
#' @export
app <- function() {
  missing_pkgs <- c()
  # Check for any missing, required packages.
  if (!requireNamespace("bslib", quietly = TRUE)) {
    missing_pkgs <- c(missing_pkgs, "bslib")
  }
  if (!requireNamespace("shiny", quietly = TRUE)) {
    missing_pkgs <- c(missing_pkgs, "shiny")
  }
  if (!requireNamespace("DT", quietly = TRUE)) {
    missing_pkgs <- c(missing_pkgs, "DT")
  }
  if (!requireNamespace("plotly", quietly = TRUE)) {
    missing_pkgs <- c(missing_pkgs, "plotly")
  }

  # If any of the required packages are missing,
  # prompt the user to install them.
  if (length(missing_pkgs) > 0) {
    cat("The following packages must be installed to run the",
      "Rnaught web application:\n"
    )
    writeLines(missing_pkgs)
    answer <- readline("Begin installation? [Y/n] ")

    if (answer == "Y" || answer == "y") {
      install.packages(missing_pkgs)
    } else {
      stop("Aborting due to missing, required packages.", call. = FALSE)
    }
  }

  shiny::runApp(appDir = system.file("app", package = "Rnaught"))
}