]> nmode's Git Repositories - Rnaught/commitdiff
Prompt user to install optional dependency
authorNaeem Model <me@nmode.ca>
Tue, 25 Jul 2023 01:50:09 +0000 (01:50 +0000)
committerNaeem Model <me@nmode.ca>
Tue, 25 Jul 2023 01:50:09 +0000 (01:50 +0000)
NAMESPACE
R/app.R
R/ui.R

index 92f1c4bbd10b31037e1cde2cb3cdc9a0d17cfe73..0508cdec5297b3e32208da9e21a106d5c8c83913 100644 (file)
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -10,5 +10,6 @@ importFrom(stats,pexp)
 importFrom(stats,pgamma)
 importFrom(stats,qexp)
 importFrom(stats,qgamma)
+importFrom(utils,install.packages)
 importFrom(utils,read.csv)
 importFrom(utils,write.csv)
diff --git a/R/app.R b/R/app.R
index feb052f3d69d9e66a079716305abc7b860b48d6a..945f9e4634d61a2052d3d0ccde41071959b18d54 100644 (file)
--- a/R/app.R
+++ b/R/app.R
@@ -1,9 +1,19 @@
 #' 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("shiny", quietly = TRUE)) {
+    answer <- readline(paste0("The package 'shiny' must be installed to ",
+      "launch the Rnaught web application.\nWould you like to install it? ",
+      "[Y/n] "))
+
+    if (answer == "Y" || answer == "y")
+      install.packages("shiny")
+    else
+      stop("Aborting.", call. = FALSE)
+  }
 
-  shiny::shinyApp(ui, server)
+  shiny::shinyApp(ui(), server)
 }
diff --git a/R/ui.R b/R/ui.R
index 4e4a500a57e94a85de127c8266b32040ed90d46c..5c6d420e833d290281ac257700eca17e8f7943ca 100644 (file)
--- a/R/ui.R
+++ b/R/ui.R
@@ -1,4 +1,4 @@
-ui <- shiny::fluidPage(
+ui <- function() { shiny::fluidPage(
   # Title.
   shiny::titlePanel(shiny::HTML(
     paste0("Rnaught: An Estimation Suite for R", shiny::tags$sub("0")))),
@@ -194,4 +194,4 @@ ui <- shiny::fluidPage(
       )
     )
   )
-)
+)}