From d555210c1784c826948384270098a09364dc4ce9 Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 14:29:51 +0000 Subject: [PATCH 1/8] extends timer to 35 seconds --- R/helper.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helper.R b/R/helper.R index a1525de..6992ee5 100644 --- a/R/helper.R +++ b/R/helper.R @@ -109,7 +109,7 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { counter <- counter + 1 Sys.sleep(1) } - if (counter > 19) cli::cli_alert_danger("Shiny app could not be started due to timeout or error") + if (counter > 35) cli::cli_alert_danger("Shiny app could not be started due to timeout or error") rstudioapi::viewer(url) From 1fcf92053dd461cf081bc95d6790cad9bc64af28 Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 14:33:06 +0000 Subject: [PATCH 2/8] updates version to 9001 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 30101b1..2a55094 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ghqc Title: Manage QC via GitHub Issues using Shiny Apps -Version: 0.2.0 +Version: 0.2.0.9001 Authors@R: c( person("Anne", "Zheng", email = "anne@a2-ai.com", role = c("aut")), person("Jenna", "Johnson", email = "jenna@a2-ai.com", role = c("aut")), From dd5194ae28fb545a9e475d68b6bcbd677d40164e Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 14:43:55 +0000 Subject: [PATCH 3/8] updates while counter --- R/helper.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/helper.R b/R/helper.R index 6992ee5..b123552 100644 --- a/R/helper.R +++ b/R/helper.R @@ -100,7 +100,7 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { cli::cli_inform("Waiting for shiny app to start...") counter <- 1 - while(counter < 20) { + while(counter < 35) { if (is_shiny_ready(url)) { cli::cli_inform("Shiny app started") break @@ -109,7 +109,7 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { counter <- counter + 1 Sys.sleep(1) } - if (counter > 35) cli::cli_alert_danger("Shiny app could not be started due to timeout or error") + if (counter > 34) cli::cli_alert_danger("Shiny app could not be started due to timeout or error") rstudioapi::viewer(url) From b017a09a65204e9f1397d79bf78a775770cf53bf Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 14:52:30 +0000 Subject: [PATCH 4/8] remove browser statements --- R/helper.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/helper.R b/R/helper.R index b123552..d2f0009 100644 --- a/R/helper.R +++ b/R/helper.R @@ -109,7 +109,9 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { counter <- counter + 1 Sys.sleep(1) } - if (counter > 34) cli::cli_alert_danger("Shiny app could not be started due to timeout or error") + if (counter > 34) { + cli::cli_alert_danger("Shiny app could not be started due to timeout or error") + } rstudioapi::viewer(url) From 0dc2bc90573727432d983b77dea46e4d1f83634a Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 17:00:50 +0000 Subject: [PATCH 5/8] adds spinner to cli while app is starting up --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ R/helper.R | 14 ++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2a55094..04e02ac 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ghqc Title: Manage QC via GitHub Issues using Shiny Apps -Version: 0.2.0.9001 +Version: 0.2.1 Authors@R: c( person("Anne", "Zheng", email = "anne@a2-ai.com", role = c("aut")), person("Jenna", "Johnson", email = "jenna@a2-ai.com", role = c("aut")), diff --git a/NEWS.md b/NEWS.md index 1524a41..f00e29e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# ghqc 0.2.1 + +- increases counter for starting up shiny apps +- adds waiter to console while app is starting up + # ghqc 0.2.0 - Updated the custom configuration options repository (now `GHQC_OPTIONS_REPO`) check to reflect the following changes: diff --git a/R/helper.R b/R/helper.R index d2f0009..eee5fee 100644 --- a/R/helper.R +++ b/R/helper.R @@ -99,17 +99,23 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { cli::cli_inform("Waiting for shiny app to start...") + sp1 <- make_spinner() + total_time <- 35 # Total wait time in seconds + interval <- 0.1 # Spinner refresh interval in seconds + iterations <- total_time / interval # Total iterations needed counter <- 1 - while(counter < 35) { + while(counter <= iterations) { + sp1$spin() if (is_shiny_ready(url)) { - cli::cli_inform("Shiny app started") + sp1$finish() + cli_alert_success("Shiny app started") break } counter <- counter + 1 - Sys.sleep(1) + Sys.sleep(interval) } - if (counter > 34) { + if (counter > iterations) { cli::cli_alert_danger("Shiny app could not be started due to timeout or error") } From 7fd8fd10686ac879814d3c0146eda14db5e6798d Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 18:32:56 +0000 Subject: [PATCH 6/8] adds error output message for users with rstudioapi 0.16.0 or greater --- R/helper.R | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/R/helper.R b/R/helper.R index eee5fee..03fa399 100644 --- a/R/helper.R +++ b/R/helper.R @@ -42,8 +42,7 @@ is_shiny_ready <- function(url) { } # is_shiny_ready #' @importFrom httpuv randomPort -#' @importFrom rstudioapi jobRunScript -#' @importFrom rstudioapi viewer +#' @importFrom rstudioapi jobRunScript jobGetState viewer #' @importFrom fs file_exists #' @importFrom withr defer run_app <- function(app_name, qc_dir, lib_path, config_path) { @@ -52,7 +51,6 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { lib_path = lib_path, config_path = config_path ) - #browser() # needed a way to create a temp file that would ran in a background job in the qc dir # the script needed to point towards the ghqc libpaths, load the package, and run the app @@ -98,8 +96,10 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { url <- sprintf("http://127.0.0.1:%s", port) + + sp1 <- cli::make_spinner() cli::cli_inform("Waiting for shiny app to start...") - sp1 <- make_spinner() + total_time <- 35 # Total wait time in seconds interval <- 0.1 # Spinner refresh interval in seconds iterations <- total_time / interval # Total iterations needed @@ -112,14 +112,33 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { break } + # if rstudioapi is >= 0.16.0, can check if there's been an error in the bgj + if (packageVersion("rstudioapi") >= "0.16.0") { + if (rstudioapi::jobGetState(job_id) == "failed") { + sp1$finish() + cli::cli_alert_danger("Shiny app could not be started due to error (see Background Jobs panel)") + break + } + } + + counter <- counter + 1 Sys.sleep(interval) } + + # check if there was a timeout if (counter > iterations) { - cli::cli_alert_danger("Shiny app could not be started due to timeout or error") + # if rstudio api is newer, it caught it eariler in the case of an error, so it's definitely a timeout + if (packageVersion("rstudioapi") >= "0.16.0") { + sp1$finish() + cli::cli_alert_danger("Shiny app could not be started due to timeout") + } + else { # else, was either a timeout or error + sp1$finish() + cli::cli_alert_danger("Shiny app could not be started due to timeout or error") + } } - rstudioapi::viewer(url) }, error = function(e){ cli::cli_alert_danger(cli::col_br_red(e$message)) From a5bf358f7dc254c525d5a186a66a2f5a764201bf Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 19:11:40 +0000 Subject: [PATCH 7/8] gets rstudioapi package versions correctly --- R/helper.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/R/helper.R b/R/helper.R index 03fa399..d44e2e0 100644 --- a/R/helper.R +++ b/R/helper.R @@ -96,6 +96,16 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { url <- sprintf("http://127.0.0.1:%s", port) + new_rstudioapi <- { + version_diff <- compareVersion(packageDescription("rstudioapi", fields = "Version"), "0.16-0") + if (version_diff < 0) { + FALSE + } + else { + TRUE + } + } + sp1 <- cli::make_spinner() cli::cli_inform("Waiting for shiny app to start...") @@ -113,7 +123,7 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { } # if rstudioapi is >= 0.16.0, can check if there's been an error in the bgj - if (packageVersion("rstudioapi") >= "0.16.0") { + if (new_rstudioapi) { if (rstudioapi::jobGetState(job_id) == "failed") { sp1$finish() cli::cli_alert_danger("Shiny app could not be started due to error (see Background Jobs panel)") @@ -129,7 +139,7 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { # check if there was a timeout if (counter > iterations) { # if rstudio api is newer, it caught it eariler in the case of an error, so it's definitely a timeout - if (packageVersion("rstudioapi") >= "0.16.0") { + if (new_rstudioapi) { sp1$finish() cli::cli_alert_danger("Shiny app could not be started due to timeout") } From 0e6ea114c2db65b7c0b2eac99ae7e2363bac3f10 Mon Sep 17 00:00:00 2001 From: jenna-a2ai Date: Wed, 11 Dec 2024 20:00:17 +0000 Subject: [PATCH 8/8] resolves pr feedback --- R/helper.R | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/R/helper.R b/R/helper.R index d44e2e0..812aa5f 100644 --- a/R/helper.R +++ b/R/helper.R @@ -96,16 +96,8 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { url <- sprintf("http://127.0.0.1:%s", port) - new_rstudioapi <- { - version_diff <- compareVersion(packageDescription("rstudioapi", fields = "Version"), "0.16-0") - if (version_diff < 0) { - FALSE - } - else { - TRUE - } - } - + # new_rstudioapi is true if its >= 0.16.0 + new_rstudioapi <- compareVersion(utils::packageDescription("rstudioapi", fields = "Version"), "0.16.0") != -1 sp1 <- cli::make_spinner() cli::cli_inform("Waiting for shiny app to start...") @@ -122,7 +114,7 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { break } - # if rstudioapi is >= 0.16.0, can check if there's been an error in the bgj + # if rstudioapi is >= 0.16.0, can use jobGetState to check if there's been an error in the bgj if (new_rstudioapi) { if (rstudioapi::jobGetState(job_id) == "failed") { sp1$finish() @@ -131,20 +123,19 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) { } } - counter <- counter + 1 Sys.sleep(interval) } # check if there was a timeout if (counter > iterations) { - # if rstudio api is newer, it caught it eariler in the case of an error, so it's definitely a timeout + sp1$finish() + + # if rstudio api is newer, it caught it earlier in the case of an error, so it's definitely a timeout if (new_rstudioapi) { - sp1$finish() cli::cli_alert_danger("Shiny app could not be started due to timeout") } else { # else, was either a timeout or error - sp1$finish() cli::cli_alert_danger("Shiny app could not be started due to timeout or error") } }