Skip to content

Commit debc4ce

Browse files
- disable and warn when mirai or renv not available
1 parent b6a1dc8 commit debc4ce

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

R/module_teal_lockfile.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ NULL
3434

3535
#' @rdname module_teal_lockfile
3636
ui_teal_lockfile <- function(id) {
37-
if (!requireNamespace("mirai", quietly = TRUE) || !requireNamespace("renv", quietly = TRUE)) {
38-
warning("lockfile feature disabled. `mirai` and `renv` packages must be installed.")
37+
if (!isTRUE(getOption("teal.renv.enable"))) {
38+
return(NULL)
39+
} else if (!.is_lockfile_deps_installed()) {
40+
warning("Lockfile feature disabled. `mirai` and `renv` packages must be installed.")
3941
return(NULL)
4042
}
4143

4244
ns <- NS(id)
43-
if (!isTRUE(getOption("teal.renv.enable"))) {
44-
return(NULL)
45-
}
4645
shiny::tagList(
4746
tags$span("", id = ns("lockFileStatus")),
4847
shinyjs::disabled(downloadLink(ns("lockFileLink"), "Download lockfile"))
@@ -51,7 +50,7 @@ ui_teal_lockfile <- function(id) {
5150

5251
#' @rdname module_teal_lockfile
5352
srv_teal_lockfile <- function(id) {
54-
if (!requireNamespace(c("mirai", "renv"), quietly = TRUE)) {
53+
if (!isTRUE(getOption("teal.renv.enable")) || !.is_lockfile_deps_installed()) {
5554
return(NULL)
5655
}
5756
moduleServer(id, function(input, output, session) {
@@ -67,10 +66,6 @@ srv_teal_lockfile <- function(id) {
6766
shinyjs::disable("lockFileLink")
6867
}
6968

70-
if (!isTRUE(getOption("teal.renv.enable"))) {
71-
return(NULL)
72-
}
73-
7469
lockfile_path <- "teal_app.lock"
7570
shiny::onStop(function() {
7671
if (file.exists(lockfile_path) && !shiny::isRunning()) {
@@ -193,3 +188,8 @@ utils::globalVariables(c("opts", "sysenv", "libpaths", "wd", "lockfilepath", "ru
193188

194189
list(out = out, res = res)
195190
}
191+
192+
#' @rdname module_teal_lockfile
193+
.is_lockfile_deps_installed <- function() {
194+
requireNamespace("mirai", quietly = TRUE) && requireNamespace("renv", quietly = TRUE)
195+
}

man/module_teal_lockfile.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)