X-Git-Url: https://git.nmode.ca/Rnaught/blobdiff_plain/9a423db7a6499d587ec2d7f02accea5baf98a8e1..94b4dcd37e662eb1e525dc241817c8dd5d4681fc:/R/app.R diff --git a/R/app.R b/R/app.R index 8048fa4..23e32ab 100644 --- a/R/app.R +++ b/R/app.R @@ -1,13 +1,39 @@ #' Launch the Rnaught Web Application #' +#' @importFrom utils install.packages +#' #' @export app <- function() { - if (!requireNamespace("shiny", quietly=TRUE)) - stop("The package 'shiny' must be installed to launch the Rnaught web application.") - if (!requireNamespace("shinyBS", quietly=TRUE)) - stop("The package 'shinyBS' must be installed to launch the Rnaught web application.") - if (!requireNamespace("shinyjs", quietly=TRUE)) - stop("The package 'shinyjs' must be installed to launch the Rnaught web application.") + 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::shinyApp(ui(), server) + shiny::runApp(appDir = system.file("app", package = "Rnaught")) }