From 73d540f407f39f1f2245f7bbaac1198c434d048a Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Wed, 12 Jun 2024 06:11:20 -0400 Subject: [PATCH 01/43] Chromote session nit Added line Chromote session initialization as a starting step for using chromote screenshot API --- R/z_pages.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/z_pages.R b/R/z_pages.R index 9945dace..444c894e 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -92,6 +92,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from manage_gh_pages(repo, to_post, local_clone, commit_message) message(sprintf( "Visualization will be available at %s\nDeployment via GitHub Pages may take a few minutes...", viz_url)) + chrome.session <- chromote::ChromoteSession$new() viz_owner_repo } From a3e9ae5617a51e22d80de0971a35bf2631a22a0c Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 17 Jun 2024 21:59:43 -0400 Subject: [PATCH 02/43] Update DESCRIPTION added chromote in suggests for testing chromote's screenshot API --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index f544e69b..c2d2118a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -100,7 +100,8 @@ Suggests: nlme, rpart, svglite, - ggplot2 + ggplot2, + chromote Remotes: ropensci/RSelenium@v1.7.4 License: GPL-3 Encoding: UTF-8 From c0e6f23b6bcb86b60b6ff656643260d001418599 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 17 Jun 2024 22:13:28 -0400 Subject: [PATCH 03/43] Update tests.yaml added chromote package for testing chromote screenshot API --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bb565b23..c6ec68ac 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -29,7 +29,7 @@ jobs: - uses: r-lib/actions/setup-r@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: digest, RJSONIO, gtable, plyr, reshape2, scales, knitr + extra-packages: digest, RJSONIO, gtable, plyr, reshape2, scales, knitr,chromote - name: install package From 492fd17afb7897ab3b9383e193d7d3916896c482 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Wed, 19 Jun 2024 00:15:59 -0400 Subject: [PATCH 04/43] Update z_pages.R changed the location of chromote init line in the code and added print to see local address of animint --- R/z_pages.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/z_pages.R b/R/z_pages.R index 444c894e..fb192347 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -49,7 +49,9 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } # Generate plot files res <- animint2dir(plot.list, open.browser = FALSE, ...) + chrome.session <- chromote::ChromoteSession$new() # Select non-ignored files to post + print(res$out.dir) all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) to_post <- all_files[!(file_info$size == 0 | grepl("~$", all_files))] @@ -92,7 +94,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from manage_gh_pages(repo, to_post, local_clone, commit_message) message(sprintf( "Visualization will be available at %s\nDeployment via GitHub Pages may take a few minutes...", viz_url)) - chrome.session <- chromote::ChromoteSession$new() + viz_owner_repo } From a466f949a5954ab31d4608699c295f84fe22146f Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Fri, 21 Jun 2024 00:25:17 -0400 Subject: [PATCH 05/43] Update z_pages.R used chromote's API of taking screenshot by navigating to url of local temporary directory --- R/z_pages.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/R/z_pages.R b/R/z_pages.R index fb192347..d29aebc7 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -36,6 +36,7 @@ #' #' @export animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) { + #print('running animint2pages') for(opt in required_opts){ if(!opt %in% names(plot.list)){ stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt)) @@ -50,8 +51,14 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from # Generate plot files res <- animint2dir(plot.list, open.browser = FALSE, ...) chrome.session <- chromote::ChromoteSession$new() + url <- paste0("file://", res$out.dir, "/index.html") + chrome$Page$navigate(url) + chrome$Page$loadEventFired() + Sys.sleep(2) # Wait for the page to load completely + + screenshot <- chrome$Page$captureScreenshot() # Select non-ignored files to post - print(res$out.dir) + #print(res$out.dir) all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) to_post <- all_files[!(file_info$size == 0 | grepl("~$", all_files))] From fde4ea0c75f9036bf73f83027beee00b434d0cc0 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Fri, 21 Jun 2024 04:15:44 -0400 Subject: [PATCH 06/43] corrected variable name corrected variable name from chrome to chrome.session --- R/z_pages.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index d29aebc7..9d2f86f5 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -52,11 +52,13 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from res <- animint2dir(plot.list, open.browser = FALSE, ...) chrome.session <- chromote::ChromoteSession$new() url <- paste0("file://", res$out.dir, "/index.html") - chrome$Page$navigate(url) - chrome$Page$loadEventFired() + chrome.session$Page$navigate(url) + chrome.session$Page$loadEventFired() Sys.sleep(2) # Wait for the page to load completely - screenshot <- chrome$Page$captureScreenshot() + screenshot <- chrome.session$Page$captureScreenshot() + screenshot_path <- file.path(res$out.dir, "screenshot.png") + writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) # Select non-ignored files to post #print(res$out.dir) all_files <- Sys.glob(file.path(res$out.dir, "*")) From d3617dc905651ad90443ed0c680f7f014794a403 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Sat, 22 Jun 2024 22:22:50 -0400 Subject: [PATCH 07/43] changed from captureScreenshot() to screenshot() changed chrome sessions captureScreenshot() API to chromote's screenshot() API to compare which option will be better. --- R/z_pages.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 9d2f86f5..013fd353 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -42,6 +42,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt)) } } + # Check for required packages for(pkg in c("gert", "gh")){ if (!requireNamespace(pkg)) { @@ -52,15 +53,13 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from res <- animint2dir(plot.list, open.browser = FALSE, ...) chrome.session <- chromote::ChromoteSession$new() url <- paste0("file://", res$out.dir, "/index.html") + chrome.session$Page$navigate(url) chrome.session$Page$loadEventFired() - Sys.sleep(2) # Wait for the page to load completely + Sys.sleep(3) + chrome.session$screenshot(filename="screenshot.png") + - screenshot <- chrome.session$Page$captureScreenshot() - screenshot_path <- file.path(res$out.dir, "screenshot.png") - writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) - # Select non-ignored files to post - #print(res$out.dir) all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) to_post <- all_files[!(file_info$size == 0 | grepl("~$", all_files))] From de2a97f614c2f345b822a1e5249a48041e7d80b1 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 24 Jun 2024 02:24:06 -0400 Subject: [PATCH 08/43] added new test to check screenshot in ghpages added new test to see if screenshot.png file exists in github pages repo. --- tests/testthat/test-compiler-ghpages.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index abefaa43..97b2b6bb 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -27,6 +27,18 @@ test_that("animint2pages() returns owner/repo string", { expect_is(viz_owner_repo, "character") }) +test_that("check if animint2pages() successfully uploads screenshot", { + #print('checking screenshot') + file_exists <- tryCatch({ + gh("GET /repos/:owner/:repo/contents/:path", + owner = "siddhesh195", repo = "animint2pages_test_repo", path = "screenshot.png",ref = "gh-pages") + TRUE # If the call succeeds, the file exists + }, error = function(e) { + FALSE # If an error occurs, assume the file does not exist + }) + expect_true(file_exists, info = "The screenshot should exist in the repository.") +}) + test_that("animint2pages raises an error if no GitHub token is present", { env.names <- c("GITHUB_PAT", "GITHUB_PAT_GITHUB_COM") env.old <- Sys.getenv(env.names) From 348cd0e6cb3e396f4323cdf69c6ab0faab1c4df0 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 24 Jun 2024 02:40:13 -0400 Subject: [PATCH 09/43] corrected hardcoded repo owner name to actual repo owner during the test corrected hardcoded repo owner name to actual repo owner during the test by getting the repo owner from animint2pages --- tests/testthat/test-compiler-ghpages.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 97b2b6bb..2690d31b 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -28,10 +28,13 @@ test_that("animint2pages() returns owner/repo string", { }) test_that("check if animint2pages() successfully uploads screenshot", { - #print('checking screenshot') + + viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo") + split_viz_owner_repo <- strsplit(viz_owner_repo, "/")[[1]] + repo_owner <- split_viz_owner_repo[1] file_exists <- tryCatch({ gh("GET /repos/:owner/:repo/contents/:path", - owner = "siddhesh195", repo = "animint2pages_test_repo", path = "screenshot.png",ref = "gh-pages") + owner = repo_owner, repo = "animint2pages_test_repo", path = "screenshot.png",ref = "gh-pages") TRUE # If the call succeeds, the file exists }, error = function(e) { FALSE # If an error occurs, assume the file does not exist From 6872e8d61edcfcb1f1618539ba04157e85fabb28 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 24 Jun 2024 02:49:34 -0400 Subject: [PATCH 10/43] corrected hardcoded repo name to actual repo name during the test corrected hardcoded repo name to actual repo name during the test --- tests/testthat/test-compiler-ghpages.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 2690d31b..5caeaede 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -32,9 +32,10 @@ test_that("check if animint2pages() successfully uploads screenshot", { viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo") split_viz_owner_repo <- strsplit(viz_owner_repo, "/")[[1]] repo_owner <- split_viz_owner_repo[1] + repo_name <- split_viz_owner_repo[2] file_exists <- tryCatch({ gh("GET /repos/:owner/:repo/contents/:path", - owner = repo_owner, repo = "animint2pages_test_repo", path = "screenshot.png",ref = "gh-pages") + owner = repo_owner, repo = repo_name, path = "screenshot.png",ref = "gh-pages") TRUE # If the call succeeds, the file exists }, error = function(e) { FALSE # If an error occurs, assume the file does not exist From bfc1b89a6caa9a4f333bd74373e519ecbad61d5c Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 24 Jun 2024 03:46:34 -0400 Subject: [PATCH 11/43] test if gh-pages branch exist test if gh-pages branch exist duting github actions testing --- tests/testthat/test-compiler-ghpages.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 5caeaede..39117482 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -33,9 +33,10 @@ test_that("check if animint2pages() successfully uploads screenshot", { split_viz_owner_repo <- strsplit(viz_owner_repo, "/")[[1]] repo_owner <- split_viz_owner_repo[1] repo_name <- split_viz_owner_repo[2] + file_exists <- tryCatch({ gh("GET /repos/:owner/:repo/contents/:path", - owner = repo_owner, repo = repo_name, path = "screenshot.png",ref = "gh-pages") + owner = repo_owner, repo = repo_name, path = "",ref ="gh-pages") TRUE # If the call succeeds, the file exists }, error = function(e) { FALSE # If an error occurs, assume the file does not exist From a358ad33f24cab1f7c05b706b81533c1ae4e9021 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 24 Jun 2024 16:37:41 -0400 Subject: [PATCH 12/43] saved screenshot to local directory added code to write data from chromote screenshot api to local dir which has animint --- R/z_pages.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 013fd353..f67ee2ce 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -54,11 +54,18 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from chrome.session <- chromote::ChromoteSession$new() url <- paste0("file://", res$out.dir, "/index.html") + + Sys.sleep(3) + chrome.session$Page$navigate(url) - chrome.session$Page$loadEventFired() + #chrome.session$Page$loadEventFired() Sys.sleep(3) - chrome.session$screenshot(filename="screenshot.png") - + + screenshot <- chrome.session$Page$captureScreenshot() + screenshot_path <- file.path(res$out.dir, "screenshot.png") + writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) + + Sys.sleep(3) all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) @@ -85,6 +92,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from repo <- gert::git_clone(origin_url, local_clone) } viz_url <- paste0("https://", owner, ".github.io/", github_repo) + print(viz_url) # check if repo has commit, if not, give it first commit, this can avoid error has_commits <- FALSE try( From 07596ac6432cb1ddbe8e7e68ff0a8225c1d23715 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Mon, 24 Jun 2024 18:16:07 -0400 Subject: [PATCH 13/43] Add file name screenshot.png to the path to query --- tests/testthat/test-compiler-ghpages.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 39117482..264ebd4d 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -36,7 +36,7 @@ test_that("check if animint2pages() successfully uploads screenshot", { file_exists <- tryCatch({ gh("GET /repos/:owner/:repo/contents/:path", - owner = repo_owner, repo = repo_name, path = "",ref ="gh-pages") + owner = repo_owner, repo = repo_name, path = "screenshot.png",ref ="gh-pages") TRUE # If the call succeeds, the file exists }, error = function(e) { FALSE # If an error occurs, assume the file does not exist From fc2bdcae9c3fb3bd0467c7bd342b5d3cfa56ce7f Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Mon, 24 Jun 2024 18:33:22 -0400 Subject: [PATCH 14/43] Remove try..catch --- tests/testthat/test-compiler-ghpages.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 264ebd4d..9f4b212c 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -34,13 +34,11 @@ test_that("check if animint2pages() successfully uploads screenshot", { repo_owner <- split_viz_owner_repo[1] repo_name <- split_viz_owner_repo[2] - file_exists <- tryCatch({ + file_exists <- { gh("GET /repos/:owner/:repo/contents/:path", owner = repo_owner, repo = repo_name, path = "screenshot.png",ref ="gh-pages") TRUE # If the call succeeds, the file exists - }, error = function(e) { - FALSE # If an error occurs, assume the file does not exist - }) + } expect_true(file_exists, info = "The screenshot should exist in the repository.") }) From 04d28e21432e6d4697a64a614f8188614db76bc2 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Mon, 24 Jun 2024 18:48:48 -0400 Subject: [PATCH 15/43] Add gh to suggests and tests.yaml --- .github/workflows/tests.yaml | 2 +- DESCRIPTION | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c6ec68ac..f9d5cdea 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -29,7 +29,7 @@ jobs: - uses: r-lib/actions/setup-r@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: digest, RJSONIO, gtable, plyr, reshape2, scales, knitr,chromote + extra-packages: digest, RJSONIO, gtable, plyr, reshape2, scales, knitr,chromote, gh - name: install package diff --git a/DESCRIPTION b/DESCRIPTION index c2d2118a..0871d807 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -101,7 +101,8 @@ Suggests: rpart, svglite, ggplot2, - chromote + chromote, + gh Remotes: ropensci/RSelenium@v1.7.4 License: GPL-3 Encoding: UTF-8 From 439dd85d6de06d4f437617d5f1173d9f1f2ea640 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Mon, 24 Jun 2024 19:00:25 -0400 Subject: [PATCH 16/43] Load library gh --- tests/testthat/test-compiler-ghpages.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 9f4b212c..83934739 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -1,5 +1,5 @@ acontext("GitHub Pages") - +library(gh) viz <- animint( title="one to ten", source="https://github.com/animint/animint2/tree/master/tests/testthat/test-compiler-ghpages.R", From de1e12c2a8aadeed75d47039c41c686aab3da6d1 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Sat, 29 Jun 2024 01:02:35 -0400 Subject: [PATCH 17/43] code for server pointing to temp directory code for server pointing to temp directory where dynamic html file is there --- R/z_pages.R | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index f67ee2ce..8a438187 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -35,6 +35,9 @@ #' } #' #' @export + + + animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) { #print('running animint2pages') for(opt in required_opts){ @@ -51,19 +54,27 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } # Generate plot files res <- animint2dir(plot.list, open.browser = FALSE, ...) + run_servr(directory = res$out.dir, port = 8080) + Sys.sleep(3) chrome.session <- chromote::ChromoteSession$new() - url <- paste0("file://", res$out.dir, "/index.html") - + #url <- paste0("file://", res$out.dir, "/index.html") + url <- sprintf("http://localhost:8080") + # + #print("sleeping") Sys.sleep(3) - chrome.session$Page$navigate(url) - #chrome.session$Page$loadEventFired() - Sys.sleep(3) - screenshot <- chrome.session$Page$captureScreenshot() screenshot_path <- file.path(res$out.dir, "screenshot.png") + + + chrome.session$Page$navigate(url) + chrome.session$Page$loadEventFired() + Sys.sleep(3) + screenshot <- chrome.session$Page$captureScreenshot() writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) + print(url) + Sys.sleep(15) Sys.sleep(3) From 80c2da31b8211659f79598ff78a70f7563879776 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Sat, 29 Jun 2024 01:18:51 -0400 Subject: [PATCH 18/43] added magick in suggests --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0871d807..3b73265d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -102,7 +102,8 @@ Suggests: svglite, ggplot2, chromote, - gh + gh, + magick Remotes: ropensci/RSelenium@v1.7.4 License: GPL-3 Encoding: UTF-8 From 1ec415b8c20d20106d582c39cb72ece2780bae74 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Sun, 30 Jun 2024 18:19:38 -0400 Subject: [PATCH 19/43] added magick in suggests --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f9d5cdea..ff1f0069 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -29,7 +29,7 @@ jobs: - uses: r-lib/actions/setup-r@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: digest, RJSONIO, gtable, plyr, reshape2, scales, knitr,chromote, gh + extra-packages: digest, RJSONIO, gtable, plyr, reshape2, scales, knitr,chromote, gh,magick - name: install package From c1f5560a8d27177a689333a1f9764e32cdfa576a Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 1 Jul 2024 00:23:50 -0400 Subject: [PATCH 20/43] testing on github actions --- R/z_pages.R | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 8a438187..67dcd863 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -1,3 +1,4 @@ + #' Publish a list of ggplots as interactive visualizations on a GitHub repository #' #' This function takes a named list of ggplots, generates interactive animations, @@ -39,7 +40,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) { - #print('running animint2pages') + for(opt in required_opts){ if(!opt %in% names(plot.list)){ stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt)) @@ -54,29 +55,28 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } # Generate plot files res <- animint2dir(plot.list, open.browser = FALSE, ...) - run_servr(directory = res$out.dir, port = 8080) - Sys.sleep(3) chrome.session <- chromote::ChromoteSession$new() - #url <- paste0("file://", res$out.dir, "/index.html") - url <- sprintf("http://localhost:8080") - - # - #print("sleeping") - Sys.sleep(3) + s<-run_servr(directory = res$out.dir, port = 2948) + #servr::httd(daemon = TRUE, port = 4321,dir=res$out.dir) + #print(s$daemon_list()) + #print(servr::servrEnv$daemon_list = list()) + url <- sprintf("http://localhost:2948") + #Sys.sleep(10) screenshot_path <- file.path(res$out.dir, "screenshot.png") - - - chrome.session$Page$navigate(url) + #print(servr::daemon_list()) chrome.session$Page$loadEventFired() Sys.sleep(3) + chrome.session$Page$navigate(url) + screenshot <- chrome.session$Page$captureScreenshot() writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) - print(url) - Sys.sleep(15) - Sys.sleep(3) + #img <- image_read(screenshot_path) + #img_trimmed <- image_trim(img) + #image_write(img_trimmed, screenshot_path) + all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) @@ -103,7 +103,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from repo <- gert::git_clone(origin_url, local_clone) } viz_url <- paste0("https://", owner, ".github.io/", github_repo) - print(viz_url) + # check if repo has commit, if not, give it first commit, this can avoid error has_commits <- FALSE try( From 12941ab20421a2f5c74f15e7ac08d7d6a557fc5f Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Mon, 1 Jul 2024 19:25:24 -0400 Subject: [PATCH 21/43] Use random port Ids to solve mac error --- R/z_pages.R | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 67dcd863..62167c4b 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -55,28 +55,28 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } # Generate plot files res <- animint2dir(plot.list, open.browser = FALSE, ...) + + portNum <- servr::random_port() chrome.session <- chromote::ChromoteSession$new() - s<-run_servr(directory = res$out.dir, port = 2948) + Sys.sleep(10) - #servr::httd(daemon = TRUE, port = 4321,dir=res$out.dir) + # Start servr and navigate to the localhost::port using chromote + normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) + code = sprintf("servr::httd(dir='%s', port=%d)", normDir, portNum) + system2("Rscript", c("-e", shQuote(code)), wait = FALSE) + Sys.sleep(20) - #print(s$daemon_list()) - #print(servr::servrEnv$daemon_list = list()) - url <- sprintf("http://localhost:2948") - #Sys.sleep(10) - screenshot_path <- file.path(res$out.dir, "screenshot.png") - #print(servr::daemon_list()) - chrome.session$Page$loadEventFired() - Sys.sleep(3) + url <- sprintf("http://localhost:%d", portNum) chrome.session$Page$navigate(url) + Sys.sleep(20) + # Capture screenshot + screenshot_path <- file.path(res$out.dir, "screenshot.png") screenshot <- chrome.session$Page$captureScreenshot() writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) + Sys.sleep(10) - #img <- image_read(screenshot_path) - #img_trimmed <- image_trim(img) - #image_write(img_trimmed, screenshot_path) - + chrome.session$close() all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) From 2653f9b29d3ee254691c888e242f088a2bfa7048 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Wed, 3 Jul 2024 00:41:26 -0400 Subject: [PATCH 22/43] added cropping feature added cropping feature using magick and set optimal values of sleep --- R/z_pages.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 62167c4b..f11bdf60 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -58,23 +58,25 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from portNum <- servr::random_port() chrome.session <- chromote::ChromoteSession$new() - Sys.sleep(10) # Start servr and navigate to the localhost::port using chromote normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) code = sprintf("servr::httd(dir='%s', port=%d)", normDir, portNum) system2("Rscript", c("-e", shQuote(code)), wait = FALSE) - Sys.sleep(20) + + Sys.sleep(3) url <- sprintf("http://localhost:%d", portNum) chrome.session$Page$navigate(url) - Sys.sleep(20) + + Sys.sleep(3) # Capture screenshot screenshot_path <- file.path(res$out.dir, "screenshot.png") screenshot <- chrome.session$Page$captureScreenshot() - writeBin(jsonlite::base64_dec(screenshot$data), screenshot_path) - Sys.sleep(10) + image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) + image_trimmed <- magick::image_trim(image_raw) + magick::image_write(image_trimmed, screenshot_path) chrome.session$close() From 5a2523f896adb21ebe48ee6e35b65a8c25bba84c Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Thu, 4 Jul 2024 14:29:36 -0400 Subject: [PATCH 23/43] start common server and copy new files to it's directory created a new persistent server for all tests in ghpages. in z_pages added code to copy files from temporary directory created by animint2dir to directory of persistent server. --- R/z_pages.R | 54 +++++++++++++++++++------- tests/testthat/test-compiler-ghpages.R | 30 +++++++++++--- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index f11bdf60..19784105 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -39,7 +39,7 @@ -animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) { +animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"),server="None", ...) { for(opt in required_opts){ if(!opt %in% names(plot.list)){ @@ -54,25 +54,49 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } } # Generate plot files - res <- animint2dir(plot.list, open.browser = FALSE, ...) - - portNum <- servr::random_port() chrome.session <- chromote::ChromoteSession$new() - # Start servr and navigate to the localhost::port using chromote - normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) - code = sprintf("servr::httd(dir='%s', port=%d)", normDir, portNum) - system2("Rscript", c("-e", shQuote(code)), wait = FALSE) - - Sys.sleep(3) - - url <- sprintf("http://localhost:%d", portNum) - chrome.session$Page$navigate(url) + if (server=="None") { + res <- animint2dir(plot.list, open.browser = FALSE, ...) + portNum <- servr::random_port() + normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) + code = sprintf("servr::httd(dir='%s', port=%d)", normDir, portNum) + system2("Rscript", c("-e", shQuote(code)), wait = FALSE) + Sys.sleep(3) + url <- sprintf("http://localhost:%d", portNum) + chrome.session$Page$navigate(url) + Sys.sleep(3) + screenshot_path <- file.path(res$out.dir, "screenshot.png") + + }else{ + res <- animint2dir(plot.list, open.browser = FALSE, ...) + #print(res$out.dir) + #print(server$output.dir) + url <- sprintf("http://localhost:%d",8080) + files_server <- list.files(server$output.dir, full.names = TRUE) + files_res <- list.files(res$out.dir, full.names = TRUE) + + for (file in files_res) { + + destination_file <- file.path(server$output.dir, sub(res$out.dir, "", file, fixed = TRUE)) + if (file.info(file)$isdir) { + dir.create(destination_file, recursive = TRUE, showWarnings = FALSE) + } else { + + dir.create(dirname(destination_file), recursive = TRUE, showWarnings = FALSE) + file.copy(file, destination_file, overwrite = TRUE) + } + } + Sys.sleep(3) + chrome.session$Page$navigate(url) + Sys.sleep(3) + screenshot_path <- file.path(res$out.dir, "screenshot.png") + + } - Sys.sleep(3) # Capture screenshot - screenshot_path <- file.path(res$out.dir, "screenshot.png") + screenshot <- chrome.session$Page$captureScreenshot() image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) image_trimmed <- magick::image_trim(image_raw) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 83934739..cb318f48 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -1,5 +1,22 @@ acontext("GitHub Pages") library(gh) + +server <- function() { + out.dir <- tempfile() + + dir.create(out.dir, showWarnings=FALSE, recursive=TRUE) + portNum <- 8080 + normDir <- normalizePath(out.dir, winslash = "/", mustWork = TRUE) + code = sprintf("servr::httd(dir='%s', port=%d)", normDir,portNum) + system2("Rscript", c("-e", shQuote(code)), wait = FALSE) + #list(out.dir) + return(list(output.dir = normDir)) +} + +s<-server() +url <- sprintf("http://localhost:%d",8080) + + viz <- animint( title="one to ten", source="https://github.com/animint/animint2/tree/master/tests/testthat/test-compiler-ghpages.R", @@ -7,29 +24,32 @@ viz <- animint( geom_point()) test_that("error for viz with no title", { + #browseURL(url) viz.no.title <- viz viz.no.title$title <- NULL expect_error({ - animint2pages(viz.no.title, "no-title") + animint2pages(viz.no.title, "no-title",server=s) }, "plot.list does not contain option named title, which is required by animint2pages") }) test_that("error for viz with no source", { + #browseURL(url) viz.no.source <- viz viz.no.source$source <- NULL expect_error({ - animint2pages(viz.no.source, "no-source") + animint2pages(viz.no.source, "no-source",server=s) }, "plot.list does not contain option named source, which is required by animint2pages") }) test_that("animint2pages() returns owner/repo string", { - viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo") + #browseURL(url) + viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo",server=s) expect_is(viz_owner_repo, "character") }) test_that("check if animint2pages() successfully uploads screenshot", { - viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo") + viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo",server=s) split_viz_owner_repo <- strsplit(viz_owner_repo, "/")[[1]] repo_owner <- split_viz_owner_repo[1] repo_name <- split_viz_owner_repo[2] @@ -55,7 +75,7 @@ test_that("animint2pages raises an error if no GitHub token is present", { file.copy(config.file, config.old, overwrite = TRUE) cat("[credential]\n\tusername = FOO", file=config.file, append=TRUE) expect_error({ - animint2pages(viz, github_repo = "test_repo") + animint2pages(viz, github_repo = "test_repo",server=s) }, "A GitHub token is required to create and push to a new repository. \nTo create a GitHub token, follow these steps:\n1. Go to https://github.com/settings/tokens/new?scopes=repo&description=animint2pages\n2. Confirm your password if prompted.\n3. Ensure that the 'repo' scope is checked.\n4. Click 'Generate token' at the bottom of the page.\n5. Copy the generated token.\nAfter creating the token, you can set it up in your R environment by running: \nSys.setenv(GITHUB_PAT=\"yourGithubPAT\") \ngert::git_config_global_set(\"user.name\", \"yourUserName\") \ngert::git_config_global_set(\"user.email\", \"yourEmail\") \n", fixed=TRUE) do.call(Sys.setenv, as.list(env.old)) file.copy(config.old, config.file, overwrite = TRUE) From 1f834d1067c7c6f6e5ace36a2454c6e1c0f0f18f Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Thu, 4 Jul 2024 14:48:57 -0400 Subject: [PATCH 24/43] removed cropping feature for debugging removed cropping feature for debugging on github actions --- R/z_pages.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 19784105..1e9cc311 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -88,6 +88,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } } Sys.sleep(3) + #browseURL(url) chrome.session$Page$navigate(url) Sys.sleep(3) screenshot_path <- file.path(res$out.dir, "screenshot.png") @@ -98,9 +99,9 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from # Capture screenshot screenshot <- chrome.session$Page$captureScreenshot() - image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) - image_trimmed <- magick::image_trim(image_raw) - magick::image_write(image_trimmed, screenshot_path) + #image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) + #image_trimmed <- magick::image_trim(image_raw) + #magick::image_write(image_trimmed, screenshot_path) chrome.session$close() From 1bf19379ae7113e6bc3ddf3badd789b94f87f4f8 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Thu, 4 Jul 2024 15:46:16 -0400 Subject: [PATCH 25/43] pass server directory into animint2dir pass server directory into animint2dir --- R/z_animint.R | 16 +++++++--- R/z_pages.R | 42 ++++++++++---------------- tests/testthat/test-compiler-ghpages.R | 7 ----- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/R/z_animint.R b/R/z_animint.R index b412bd45..8f649782 100644 --- a/R/z_animint.R +++ b/R/z_animint.R @@ -248,15 +248,18 @@ storeLayer <- function(meta, g, g.data.varied){ #' @example inst/examples/animint2dir.R animint2dir <- function(plot.list, out.dir = NULL, json.file = "plot.json", open.browser = interactive(), - css.file = "") { + css.file = "",persistent_server=FALSE, ...) { if(is.null(out.dir)){ out.dir <- tempfile() } animint.js <- file.path(out.dir, "animint.js") - if(dir.exists(out.dir) && !file.exists(animint.js)){ + if(dir.exists(out.dir) && !file.exists(animint.js) && persistent_server==FALSE){ stop(animint.js, " does not exist, so not removing out.dir. If you really want to save your animint in out.dir, then please remove that directory entirely") } - unlink(out.dir, recursive=TRUE) + if(persistent_server==FALSE){ + unlink(out.dir, recursive=TRUE) + } + ## Check plot.list for errors checkPlotList(plot.list) @@ -264,7 +267,12 @@ animint2dir <- function(plot.list, out.dir = NULL, ## lower-level functions. meta <- newEnvironment() meta$selector.types <- plot.list$selector.types - dir.create(out.dir,showWarnings=FALSE) + if(persistent_server==FALSE){ + + dir.create(out.dir,showWarnings=FALSE) + + } + meta$out.dir <- out.dir ## First, copy html/js/json files to out.dir. src.dir <- system.file("htmljs",package="animint2") diff --git a/R/z_pages.R b/R/z_pages.R index 1e9cc311..69eea84f 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -39,7 +39,7 @@ -animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"),server="None", ...) { +animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"),server=NULL, ...) { for(opt in required_opts){ if(!opt %in% names(plot.list)){ @@ -54,9 +54,14 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } } # Generate plot files + res <- animint2dir(plot.list, open.browser = FALSE, ...) + + portNum <- servr::random_port() chrome.session <- chromote::ChromoteSession$new() - if (server=="None") { + + if (is.null(server)) { + #print("if condition") res <- animint2dir(plot.list, open.browser = FALSE, ...) portNum <- servr::random_port() normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) @@ -65,43 +70,28 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from Sys.sleep(3) url <- sprintf("http://localhost:%d", portNum) chrome.session$Page$navigate(url) - Sys.sleep(3) - screenshot_path <- file.path(res$out.dir, "screenshot.png") }else{ - res <- animint2dir(plot.list, open.browser = FALSE, ...) + #print("else condition") + res <- animint2dir(plot.list, open.browser = FALSE,out.dir=server$output.dir,persistent_server=TRUE, ...) #print(res$out.dir) #print(server$output.dir) url <- sprintf("http://localhost:%d",8080) - files_server <- list.files(server$output.dir, full.names = TRUE) - files_res <- list.files(res$out.dir, full.names = TRUE) - - for (file in files_res) { - - destination_file <- file.path(server$output.dir, sub(res$out.dir, "", file, fixed = TRUE)) - if (file.info(file)$isdir) { - dir.create(destination_file, recursive = TRUE, showWarnings = FALSE) - } else { - - dir.create(dirname(destination_file), recursive = TRUE, showWarnings = FALSE) - file.copy(file, destination_file, overwrite = TRUE) - } - } - Sys.sleep(3) #browseURL(url) chrome.session$Page$navigate(url) - Sys.sleep(3) - screenshot_path <- file.path(res$out.dir, "screenshot.png") } + #Sys.sleep(3) + screenshot_path <- file.path(res$out.dir, "screenshot.png") + chrome.session$Page$navigate(url) + Sys.sleep(3) # Capture screenshot - screenshot <- chrome.session$Page$captureScreenshot() - #image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) - #image_trimmed <- magick::image_trim(image_raw) - #magick::image_write(image_trimmed, screenshot_path) + image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) + image_trimmed <- magick::image_trim(image_raw) + magick::image_write(image_trimmed, screenshot_path) chrome.session$close() diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index cb318f48..e4d6d0a3 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -1,6 +1,5 @@ acontext("GitHub Pages") library(gh) - server <- function() { out.dir <- tempfile() @@ -14,9 +13,6 @@ server <- function() { } s<-server() -url <- sprintf("http://localhost:%d",8080) - - viz <- animint( title="one to ten", source="https://github.com/animint/animint2/tree/master/tests/testthat/test-compiler-ghpages.R", @@ -24,7 +20,6 @@ viz <- animint( geom_point()) test_that("error for viz with no title", { - #browseURL(url) viz.no.title <- viz viz.no.title$title <- NULL expect_error({ @@ -33,7 +28,6 @@ test_that("error for viz with no title", { }) test_that("error for viz with no source", { - #browseURL(url) viz.no.source <- viz viz.no.source$source <- NULL expect_error({ @@ -42,7 +36,6 @@ test_that("error for viz with no source", { }) test_that("animint2pages() returns owner/repo string", { - #browseURL(url) viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo",server=s) expect_is(viz_owner_repo, "character") }) From baabd4f6e94d6c9f43f0c1c1b858f601e0eb9bd4 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Fri, 5 Jul 2024 22:34:11 -0400 Subject: [PATCH 26/43] fixed server error, updated version, added NEWS --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/z_pages.R | 12 ++---------- tests/testthat/test-compiler-ghpages.R | 3 +-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3b73265d..42067261 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: animint2 Title: Animated Interactive Grammar of Graphics -Version: 2024.3.12 +Version: 2024.7.5 URL: https://animint.github.io/animint2/ BugReports: https://github.com/animint/animint2/issues Authors@R: c( diff --git a/NEWS.md b/NEWS.md index c8da2989..22b0b457 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# Changes in version 2024.7.5 (PR#131) + + - Added functionality to capture screenshot in animint2page + # Changes in version 2024.3.12 (PR#119) - Add validation checks for duplicate args passed geom and aes diff --git a/R/z_pages.R b/R/z_pages.R index 69eea84f..32d308e5 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -61,7 +61,6 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from if (is.null(server)) { - #print("if condition") res <- animint2dir(plot.list, open.browser = FALSE, ...) portNum <- servr::random_port() normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) @@ -70,20 +69,13 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from Sys.sleep(3) url <- sprintf("http://localhost:%d", portNum) chrome.session$Page$navigate(url) - }else{ - #print("else condition") res <- animint2dir(plot.list, open.browser = FALSE,out.dir=server$output.dir,persistent_server=TRUE, ...) - #print(res$out.dir) - #print(server$output.dir) url <- sprintf("http://localhost:%d",8080) - #browseURL(url) chrome.session$Page$navigate(url) - } - #Sys.sleep(3) - screenshot_path <- file.path(res$out.dir, "screenshot.png") - chrome.session$Page$navigate(url) + + screenshot_path <- file.path(res$out.dir, "Capture.PNG") Sys.sleep(3) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index e4d6d0a3..6b49e903 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -8,7 +8,6 @@ server <- function() { normDir <- normalizePath(out.dir, winslash = "/", mustWork = TRUE) code = sprintf("servr::httd(dir='%s', port=%d)", normDir,portNum) system2("Rscript", c("-e", shQuote(code)), wait = FALSE) - #list(out.dir) return(list(output.dir = normDir)) } @@ -49,7 +48,7 @@ test_that("check if animint2pages() successfully uploads screenshot", { file_exists <- { gh("GET /repos/:owner/:repo/contents/:path", - owner = repo_owner, repo = repo_name, path = "screenshot.png",ref ="gh-pages") + owner = repo_owner, repo = repo_name, path = "Capture.PNG",ref ="gh-pages") TRUE # If the call succeeds, the file exists } expect_true(file_exists, info = "The screenshot should exist in the repository.") From dec0650d33d5150d80047761a7a07d8de1255d34 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Wed, 10 Jul 2024 08:55:30 -0400 Subject: [PATCH 27/43] corrected name of the function corrected name of the function --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 22b0b457..87e2b095 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # Changes in version 2024.7.5 (PR#131) - - Added functionality to capture screenshot in animint2page + - Added functionality to capture screenshot in animint2pages # Changes in version 2024.3.12 (PR#119) From 8241ea81e726d88b1dda8c35aa07655d892c056b Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Fri, 12 Jul 2024 03:48:26 -0400 Subject: [PATCH 28/43] removed duplicate lines and whitespaces --- R/z_pages.R | 7 ------- 1 file changed, 7 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 32d308e5..f506f862 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -53,12 +53,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from stop(sprintf("Please run `install.packages('%s')` before using this function", pkg)) } } - # Generate plot files - res <- animint2dir(plot.list, open.browser = FALSE, ...) - - portNum <- servr::random_port() chrome.session <- chromote::ChromoteSession$new() - if (is.null(server)) { res <- animint2dir(plot.list, open.browser = FALSE, ...) @@ -76,9 +71,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from } screenshot_path <- file.path(res$out.dir, "Capture.PNG") - Sys.sleep(3) - # Capture screenshot screenshot <- chrome.session$Page$captureScreenshot() image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) From de42e290a07d7f9a57408c6c48458e8938d76e65 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Thu, 29 Aug 2024 01:02:29 -0400 Subject: [PATCH 29/43] removed empty line --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5a595f17..bda66d18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -104,7 +104,6 @@ Suggests: chromote, gh, magick - License: GPL-3 Encoding: UTF-8 LazyData: true From 82c998c1994e7caaa07b407f1d501b9907eb09db Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Thu, 29 Aug 2024 01:20:03 -0400 Subject: [PATCH 30/43] removed empty line --- NEWS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 5f69a892..663219dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,3 @@ - # Changes in version 2024.8.29 (PR#131) - Added functionality to capture screenshot in animint2pages From 20bd120c4f31cbe33ebded2fc3e88f5009dc640e Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Thu, 29 Aug 2024 10:05:34 -0400 Subject: [PATCH 31/43] screenshot excludes widgets --- R/z_pages.R | 25 ++++++++----------------- inst/htmljs/animint.js | 23 +++++++++++++---------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index f506f862..9ffbd335 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -36,25 +36,19 @@ #' } #' #' @export - - - animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"),server=NULL, ...) { - for(opt in required_opts){ if(!opt %in% names(plot.list)){ stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt)) } } - - # Check for required packages + ## Check for required packages for(pkg in c("gert", "gh")){ if (!requireNamespace(pkg)) { stop(sprintf("Please run `install.packages('%s')` before using this function", pkg)) } } chrome.session <- chromote::ChromoteSession$new() - if (is.null(server)) { res <- animint2dir(plot.list, open.browser = FALSE, ...) portNum <- servr::random_port() @@ -69,17 +63,16 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from url <- sprintf("http://localhost:%d",8080) chrome.session$Page$navigate(url) } - screenshot_path <- file.path(res$out.dir, "Capture.PNG") + screenshot_full <- file.path(res$out.dir, "Capture_full.PNG") Sys.sleep(3) - # Capture screenshot - screenshot <- chrome.session$Page$captureScreenshot() - image_raw <- magick::image_read(jsonlite::base64_dec(screenshot$data)) + ## Capture screenshot + chrome.session$screenshot(screenshot_full, selector = ".plot_content") + image_raw <- magick::image_read(screenshot_full) image_trimmed <- magick::image_trim(image_raw) magick::image_write(image_trimmed, screenshot_path) - + unlink(screenshot_full) chrome.session$close() - all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) to_post <- all_files[!(file_info$size == 0 | grepl("~$", all_files))] @@ -105,8 +98,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from repo <- gert::git_clone(origin_url, local_clone) } viz_url <- paste0("https://", owner, ".github.io/", github_repo) - - # check if repo has commit, if not, give it first commit, this can avoid error + ## check if repo has commit, if not, give it first commit, this can avoid error has_commits <- FALSE try( { @@ -119,11 +111,10 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from if (!has_commits) { initial_commit(local_clone, repo, viz_url) } - # Handle gh-pages branch + ## Handle gh-pages branch manage_gh_pages(repo, to_post, local_clone, commit_message) message(sprintf( "Visualization will be available at %s\nDeployment via GitHub Pages may take a few minutes...", viz_url)) - viz_owner_repo } diff --git a/inst/htmljs/animint.js b/inst/htmljs/animint.js index d77109c3..a8244697 100644 --- a/inst/htmljs/animint.js +++ b/inst/htmljs/animint.js @@ -148,6 +148,10 @@ var animint = function (to_select, json_file) { var element = d3.select(to_select); this.element = element; var viz_id = element.attr("id"); + var plot_widget_table = element.append("table"); + var plot_td = plot_widget_table.append("tr").append("td"); + plot_td.attr("class","plot_content"); + var widget_td = plot_widget_table.append("tr").append("td"); var Widgets = {}; this.Widgets = Widgets; var Selectors = {}; @@ -218,7 +222,7 @@ var animint = function (to_select, json_file) { // Each plot may have one or more legends. To make space for the // legends, we put each plot in a table with one row and two // columns: tdLeft and tdRight. - var plot_table = element.append("table").style("display", "inline-block"); + var plot_table = plot_td.append("table").style("display", "inline-block"); var plot_tr = plot_table.append("tr"); var tdLeft = plot_tr.append("td"); var tdRight = plot_tr.append("td").attr("class", p_name+"_legend"); @@ -303,7 +307,7 @@ var animint = function (to_select, json_file) { return measureText(entry, p_info.ysize).width + 5; })); } - var axispaddingx = 10 + 20; + var axispaddingx = 30; // distance between tick marks and x axis name. if(p_info.hasOwnProperty("xlabs") && p_info.xlabs.length){ // TODO: throw warning if text height is large portion of plot height? axispaddingx += Math.max.apply(null, p_info.xlabs.map(function(entry){ @@ -2049,15 +2053,14 @@ var animint = function (to_select, json_file) { //////////////////////////////////////////// // Widgets at bottom of page //////////////////////////////////////////// - element.append("br"); if(response.hasOwnProperty("source")){ - element.append("a") + widget_td.append("a") .attr("id","a_source_href") .attr("href", response.source) .text("source"); } // loading table. - var show_hide_table = element.append("button") + var show_hide_table = widget_td.append("button") .text("Show download status table"); show_hide_table .on("click", function(){ @@ -2069,7 +2072,7 @@ var animint = function (to_select, json_file) { show_hide_table.text("Show download status table"); } }); - var loading = element.append("table") + var loading = widget_td.append("table") .style("display", "none"); Widgets["loading"] = loading; var tr = loading.append("tr"); @@ -2087,7 +2090,7 @@ var animint = function (to_select, json_file) { // Animation control widgets. var show_message = "Show animation controls"; // add a button to view the animation widgets - var show_hide_animation_controls = element.append("button") + var show_hide_animation_controls = widget_td.append("button") .text(show_message) .attr("id", viz_id + "_show_hide_animation_controls") .on("click", function(){ @@ -2101,7 +2104,7 @@ var animint = function (to_select, json_file) { }) ; // table of the animint widgets - var time_table = element.append("table") + var time_table = widget_td.append("table") .style("display", "none"); var first_tr = time_table.append("tr"); var first_th = first_tr.append("th"); @@ -2178,13 +2181,13 @@ var animint = function (to_select, json_file) { d3.select(".urltable").style("display","none") } } - var show_hide_selector_widgets = element.append("button") + var show_hide_selector_widgets = widget_td.append("button") .text(toggle_message) .attr("class", "show_hide_selector_widgets") .on("click", show_or_hide_fun) ; // adding a table for selector widgets - var selector_table = element.append("table") + var selector_table = widget_td.append("table") .style("display", "none") .attr("class", "table_selector_widgets") ; From fc23ea2b6dda1e8be82a6b9ec8f9732bcb1e8e1d Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Thu, 29 Aug 2024 10:16:14 -0400 Subject: [PATCH 32/43] animint2pages example add title, source, color --- DESCRIPTION | 1 - R/z_pages.R | 22 +++++++++++----------- man/animint2dir.Rd | 4 +++- man/animint2pages.Rd | 21 +++++++++++---------- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bda66d18..80192444 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -102,7 +102,6 @@ Suggests: svglite, ggplot2, chromote, - gh, magick License: GPL-3 Encoding: UTF-8 diff --git a/R/z_pages.R b/R/z_pages.R index 9ffbd335..7ef8481e 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -23,18 +23,18 @@ #' @examples #' \dontrun{ #' library(animint2) -#' p1 <- ggplot(mtcars, aes(x = mpg, y = wt)) + -#' geom_point() -#' p2 <- ggplot(mtcars, aes(x = hp, y = wt)) + -#' geom_point() -#' viz <- list(plot1 = p1, plot2 = p2) -#' animint2pages( -#' viz, -#' github_repo = "my_animint2_plots", -#' commit_message = "New animint", -#' private = TRUE) +#' mtcars$Cyl <- factor(mtcars$cyl) +#' viz <- animint( +#' ggplot(mtcars, aes(x = mpg, y = disp, color=Cyl)) + +#' geom_point(), +#' ggplot(mtcars, aes(x = hp, y = wt, color=Cyl)) + +#' geom_point(), +#' title="Motor Trend Cars data viz", +#' source="https://github.com/animint/animint2/blob/master/R/z_pages.R" +#' ) +#' animint2pages(viz, "animint2pages-example-mtcars") #' } -#' +#' #' @export animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"),server=NULL, ...) { for(opt in required_opts){ diff --git a/man/animint2dir.Rd b/man/animint2dir.Rd index f5d3176a..77cd7c99 100644 --- a/man/animint2dir.Rd +++ b/man/animint2dir.Rd @@ -9,7 +9,9 @@ animint2dir( out.dir = NULL, json.file = "plot.json", open.browser = interactive(), - css.file = "" + css.file = "", + persistent_server = FALSE, + ... ) } \arguments{ diff --git a/man/animint2pages.Rd b/man/animint2pages.Rd index 0c3b0093..8e9498b7 100644 --- a/man/animint2pages.Rd +++ b/man/animint2pages.Rd @@ -10,6 +10,7 @@ animint2pages( commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title", "source"), + server = NULL, ... ) } @@ -43,16 +44,16 @@ Before using this function set your appropriate git 'user.username' and 'user.em \examples{ \dontrun{ library(animint2) -p1 <- ggplot(mtcars, aes(x = mpg, y = wt)) + - geom_point() -p2 <- ggplot(mtcars, aes(x = hp, y = wt)) + - geom_point() -viz <- list(plot1 = p1, plot2 = p2) -animint2pages( - viz, - github_repo = "my_animint2_plots", - commit_message = "New animint", - private = TRUE) +mtcars$Cyl <- factor(mtcars$cyl) +viz <- animint( + ggplot(mtcars, aes(x = mpg, y = disp, color=Cyl)) + + geom_point(), + ggplot(mtcars, aes(x = hp, y = wt, color=Cyl)) + + geom_point(), + title="Motor Trend Cars data viz", + source="https://github.com/animint/animint2/blob/master/R/z_pages.R" +) +animint2pages(viz, "animint2pages-example-mtcars") } } From 75bf9826fba7f22250e41021b24e2a098299c1ab Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Thu, 29 Aug 2024 17:50:25 -0400 Subject: [PATCH 33/43] added empty line and space --- R/z_pages.R | 2 +- tests/testthat/test-compiler-ghpages.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 7ef8481e..9bd54f5a 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -36,7 +36,7 @@ #' } #' #' @export -animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"),server=NULL, ...) { +animint2pages <- function(plot.list, github_repo, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), server=NULL, ...) { for(opt in required_opts){ if(!opt %in% names(plot.list)){ stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt)) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 6b49e903..aadd2e86 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -2,7 +2,6 @@ acontext("GitHub Pages") library(gh) server <- function() { out.dir <- tempfile() - dir.create(out.dir, showWarnings=FALSE, recursive=TRUE) portNum <- 8080 normDir <- normalizePath(out.dir, winslash = "/", mustWork = TRUE) @@ -12,6 +11,7 @@ server <- function() { } s<-server() + viz <- animint( title="one to ten", source="https://github.com/animint/animint2/tree/master/tests/testthat/test-compiler-ghpages.R", From 3b98e9cfeec52e0a92713792b81626e2b2548fd3 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Sat, 31 Aug 2024 21:59:04 -0400 Subject: [PATCH 34/43] test passes without persistent server --- tests/testthat/test-compiler-ghpages.R | 39 ++++++-------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/tests/testthat/test-compiler-ghpages.R b/tests/testthat/test-compiler-ghpages.R index 54edd382..9404d62f 100644 --- a/tests/testthat/test-compiler-ghpages.R +++ b/tests/testthat/test-compiler-ghpages.R @@ -1,17 +1,4 @@ acontext("GitHub Pages") -library(gh) -server <- function() { - out.dir <- tempfile() - dir.create(out.dir, showWarnings=FALSE, recursive=TRUE) - portNum <- 8080 - normDir <- normalizePath(out.dir, winslash = "/", mustWork = TRUE) - code = sprintf("servr::httd(dir='%s', port=%d)", normDir,portNum) - system2("Rscript", c("-e", shQuote(code)), wait = FALSE) - return(list(output.dir = normDir)) -} - -s<-server() - library(animint2) viz <- animint( title="one to ten", @@ -23,7 +10,7 @@ test_that("error for viz with no title", { viz.no.title <- viz viz.no.title$title <- NULL expect_error({ - animint2pages(viz.no.title, "no-title",server=s) + animint2pages(viz.no.title, "no-title") }, "plot.list does not contain option named title, which is required by animint2pages") }) @@ -31,7 +18,7 @@ test_that("error for viz with no source", { viz.no.source <- viz viz.no.source$source <- NULL expect_error({ - animint2pages(viz.no.source, "no-source",server=s) + animint2pages(viz.no.source, "no-source") }, "plot.list does not contain option named source, which is required by animint2pages") }) @@ -58,6 +45,10 @@ test_that("animint2pages() returns list of meta-data", { get_tsv <- function(L)Sys.glob(file.path(L$local_clone, "*tsv")) tsv_files_created <- get_tsv(result_list) expect_equal(length(tsv_files_created), 1) + expect_Capture <- function(L){ + expect_gt(file.size(file.path(L$local_clone,"Capture.PNG")), 0) + } + expect_Capture(result_list) ## second run of animint2pages updates data viz. viz.more <- viz viz.more$five <- ggplot()+ @@ -67,21 +58,7 @@ test_that("animint2pages() returns list of meta-data", { update_list <- animint2pages(viz.more, "animint2pages_test_repo", owner="animint-test") tsv_files_updated <- get_tsv(update_list) expect_equal(length(tsv_files_updated), 2) -}) - -test_that("check if animint2pages() successfully uploads screenshot", { - - viz_owner_repo <- animint2pages(viz, github_repo = "animint2pages_test_repo",server=s) - split_viz_owner_repo <- strsplit(viz_owner_repo, "/")[[1]] - repo_owner <- split_viz_owner_repo[1] - repo_name <- split_viz_owner_repo[2] - - file_exists <- { - gh("GET /repos/:owner/:repo/contents/:path", - owner = repo_owner, repo = repo_name, path = "Capture.PNG",ref ="gh-pages") - TRUE # If the call succeeds, the file exists - } - expect_true(file_exists, info = "The screenshot should exist in the repository.") + expect_Capture(update_list) }) test_that("animint2pages raises an error if no GitHub token is present", { @@ -97,7 +74,7 @@ test_that("animint2pages raises an error if no GitHub token is present", { file.copy(config.file, config.old, overwrite = TRUE) cat("[credential]\n\tusername = FOO", file=config.file, append=TRUE) expect_error({ - animint2pages(viz, github_repo = "test_repo",server=s) + animint2pages(viz, github_repo = "test_repo") }, "A GitHub token is required to create and push to a new repository. \nTo create a GitHub token, follow these steps:\n1. Go to https://github.com/settings/tokens/new?scopes=repo&description=animint2pages\n2. Confirm your password if prompted.\n3. Ensure that the 'repo' scope is checked.\n4. Click 'Generate token' at the bottom of the page.\n5. Copy the generated token.\nAfter creating the token, you can set it up in your R environment by running: \nSys.setenv(GITHUB_PAT=\"yourGithubPAT\") \ngert::git_config_global_set(\"user.name\", \"yourUserName\") \ngert::git_config_global_set(\"user.email\", \"yourEmail\") \n", fixed=TRUE) do.call(Sys.setenv, as.list(env.old)) file.copy(config.old, config.file, overwrite = TRUE) From c7dca849e32febd13b7d48b7baf1cf17d1060b58 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Sat, 14 Sep 2024 13:31:20 -0400 Subject: [PATCH 35/43] Remove empty lines --- R/z_animint.R | 4 ---- R/z_pages.R | 1 - 2 files changed, 5 deletions(-) diff --git a/R/z_animint.R b/R/z_animint.R index 8f649782..08fb932d 100644 --- a/R/z_animint.R +++ b/R/z_animint.R @@ -259,7 +259,6 @@ animint2dir <- function(plot.list, out.dir = NULL, if(persistent_server==FALSE){ unlink(out.dir, recursive=TRUE) } - ## Check plot.list for errors checkPlotList(plot.list) @@ -268,11 +267,8 @@ animint2dir <- function(plot.list, out.dir = NULL, meta <- newEnvironment() meta$selector.types <- plot.list$selector.types if(persistent_server==FALSE){ - dir.create(out.dir,showWarnings=FALSE) - } - meta$out.dir <- out.dir ## First, copy html/js/json files to out.dir. src.dir <- system.file("htmljs",package="animint2") diff --git a/R/z_pages.R b/R/z_pages.R index 3a591be9..b75f6a97 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -1,4 +1,3 @@ - #' Publish a list of ggplots as interactive visualizations on a GitHub repository #' #' This function takes a named list of ggplots, generates interactive animations, From b12a42ff3189529c0c9e6622ba9be1af08d3e684 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Sat, 14 Sep 2024 22:22:33 -0400 Subject: [PATCH 36/43] Refactor to reuse start_server --- NAMESPACE | 2 ++ R/utilities.r | 26 ++++++++++++++++++++++++++ tests/testthat/helper-functions.R | 20 +++----------------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index c6dc730f..39c5cc32 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -446,6 +446,7 @@ export(scale_y_log10) export(scale_y_reverse) export(scale_y_sqrt) export(should_stop) +export(start_servr) export(stat_bin) export(stat_bin2d) export(stat_bin_2d) @@ -471,6 +472,7 @@ export(stat_summary_bin) export(stat_summary_hex) export(stat_unique) export(stat_ydensity) +export(stop_server) export(theme) export(theme_animint) export(theme_bw) diff --git a/R/utilities.r b/R/utilities.r index 8e100e78..acc4905f 100644 --- a/R/utilities.r +++ b/R/utilities.r @@ -280,3 +280,29 @@ dispatch_args <- function(f, ...) { formals(f) <- formals f } + +start_servr <- function(serverDirectory = ".", port = 4848, + code = "servr::httd(dir='%s', port=%d)", + tmpPath = ".") { + dir <- normalizePath(serverDirectory, winslash = "/", mustWork = TRUE) + cmd <- sprintf( + paste("write.table(Sys.getpid(), file='%s', append=T, row.name=F, col.names=F);", code), + file.path(tmpPath, "pids.txt"), dir, port + ) + system2("Rscript", c("-e", shQuote(cmd)), wait = FALSE) +} + +stop_server <- function(tmpPath = ".") { + res <- TRUE + f <- file.path(tmpPath, "pids.txt") + if (file.exists(f)) { + e <- try(readLines(con <- file(f), warn = FALSE), silent = TRUE) + if (!inherits(e, "try-error")) { + pids <- as.integer(e) + res <- c(res, tools::pskill(pids)) + } + close(con) + unlink(f) + } + res +} diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index 9e26dfc0..604d5da1 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -351,18 +351,9 @@ tests_run <- function(dir = ".", filter = NULL) { #' @seealso \link{tests_run} #' @export tests_exit <- function() { - res <- stop_binary() + stop_binary() Sys.unsetenv("ANIMINT_BROWSER") - f <- file.path(find_test_path(), "pids.txt") - if (file.exists(f)) { - e <- try(readLines(con <- file(f), warn = FALSE), silent = TRUE) - if (!inherits(e, "try-error")) { - pids <- as.integer(e) - res <- c(res, tools::pskill(pids)) - } - close(con) - unlink(f) - } + res <- stop_server(tmpPath = find_test_path()) invisible(all(res)) } @@ -376,12 +367,7 @@ tests_exit <- function() { #' @return port number of the successful attempt run_servr <- function(directory = ".", port = 4848, code = "servr::httd(dir='%s', port=%d)") { - dir <- normalizePath(directory, winslash = "/", mustWork = TRUE) - cmd <- sprintf( - paste("write.table(Sys.getpid(), file='%s', append=T, row.name=F, col.names=F);", code), - file.path(find_test_path(), "pids.txt"), dir, port - ) - system2("Rscript", c("-e", shQuote(cmd)), wait = FALSE) + start_servr(directory, port, code, tmpPath = find_test_path()) } # -------------------------- From 445cbc4cdedfe4f3459dbb8aeb72fd876c529331 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Sun, 15 Sep 2024 02:13:02 -0400 Subject: [PATCH 37/43] Delete persistent server --- R/z_animint.R | 12 ++++-------- R/z_pages.R | 23 ++++++++--------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/R/z_animint.R b/R/z_animint.R index 08fb932d..a7902f6e 100644 --- a/R/z_animint.R +++ b/R/z_animint.R @@ -248,17 +248,15 @@ storeLayer <- function(meta, g, g.data.varied){ #' @example inst/examples/animint2dir.R animint2dir <- function(plot.list, out.dir = NULL, json.file = "plot.json", open.browser = interactive(), - css.file = "",persistent_server=FALSE, ...) { + css.file = "", ...) { if(is.null(out.dir)){ out.dir <- tempfile() } animint.js <- file.path(out.dir, "animint.js") - if(dir.exists(out.dir) && !file.exists(animint.js) && persistent_server==FALSE){ + if(dir.exists(out.dir) && !file.exists(animint.js)){ stop(animint.js, " does not exist, so not removing out.dir. If you really want to save your animint in out.dir, then please remove that directory entirely") } - if(persistent_server==FALSE){ - unlink(out.dir, recursive=TRUE) - } + unlink(out.dir, recursive=TRUE) ## Check plot.list for errors checkPlotList(plot.list) @@ -266,9 +264,7 @@ animint2dir <- function(plot.list, out.dir = NULL, ## lower-level functions. meta <- newEnvironment() meta$selector.types <- plot.list$selector.types - if(persistent_server==FALSE){ - dir.create(out.dir,showWarnings=FALSE) - } + dir.create(out.dir,showWarnings=FALSE) meta$out.dir <- out.dir ## First, copy html/js/json files to out.dir. src.dir <- system.file("htmljs",package="animint2") diff --git a/R/z_pages.R b/R/z_pages.R index b75f6a97..690eac24 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -36,7 +36,7 @@ #' } #' #' @export -animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), server=NULL, ...) { +animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = "Commit from animint2pages", private = FALSE, required_opts = c("title","source"), ...) { for(opt in required_opts){ if(!opt %in% names(plot.list)){ stop(sprintf("plot.list does not contain option named %s, which is required by animint2pages", opt)) @@ -49,20 +49,13 @@ animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = " } } chrome.session <- chromote::ChromoteSession$new() - if (is.null(server)) { - res <- animint2dir(plot.list, open.browser = FALSE, ...) - portNum <- servr::random_port() - normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) - code = sprintf("servr::httd(dir='%s', port=%d)", normDir, portNum) - system2("Rscript", c("-e", shQuote(code)), wait = FALSE) - Sys.sleep(3) - url <- sprintf("http://localhost:%d", portNum) - chrome.session$Page$navigate(url) - }else{ - res <- animint2dir(plot.list, open.browser = FALSE,out.dir=server$output.dir,persistent_server=TRUE, ...) - url <- sprintf("http://localhost:%d",8080) - chrome.session$Page$navigate(url) - } + res <- animint2dir(plot.list, open.browser = FALSE, ...) + portNum <- servr::random_port() + normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) + start_servr(serverDirectory = normDir, port = portNum, tmpPath = normDir) + Sys.sleep(3) + url <- sprintf("http://localhost:%d", portNum) + chrome.session$Page$navigate(url) screenshot_path <- file.path(res$out.dir, "Capture.PNG") screenshot_full <- file.path(res$out.dir, "Capture_full.PNG") Sys.sleep(3) From 2603e3b7963d7c570051d2111d5dfe0bcf8e4032 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Tue, 17 Sep 2024 16:36:15 -0400 Subject: [PATCH 38/43] Stop the server after capturing screensjot --- R/z_pages.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/z_pages.R b/R/z_pages.R index 690eac24..6f07bbf7 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -50,6 +50,7 @@ animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = " } chrome.session <- chromote::ChromoteSession$new() res <- animint2dir(plot.list, open.browser = FALSE, ...) + #Find available port and start server portNum <- servr::random_port() normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) start_servr(serverDirectory = normDir, port = portNum, tmpPath = normDir) @@ -66,6 +67,8 @@ animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = " magick::image_write(image_trimmed, screenshot_path) unlink(screenshot_full) chrome.session$close() + # Stop the server + stop_server(normDir) all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) to_post <- all_files[!(file_info$size == 0 | grepl("~$", all_files))] From 9375dca0a3fefc8a43b0dec9deaa6e281b6d236d Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Wed, 18 Sep 2024 09:34:50 -0400 Subject: [PATCH 39/43] Increment version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 80192444..8d73830a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: animint2 Title: Animated Interactive Grammar of Graphics -Version: 2024.8.29 +Version: 2024.9.18 URL: https://animint.github.io/animint2/ BugReports: https://github.com/animint/animint2/issues Authors@R: c( From 1b81662c0755e04bc4ecb5850cd6d0e3ebc46876 Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Thu, 19 Sep 2024 14:08:31 -0400 Subject: [PATCH 40/43] Delete stop_binary, check that package is loaded before taking screenshot --- R/z_pages.R | 45 ++++++++++++++++--------------- tests/testthat/helper-functions.R | 15 +---------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/R/z_pages.R b/R/z_pages.R index 6f07bbf7..ee016ee3 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -48,27 +48,30 @@ animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = " stop(sprintf("Please run `install.packages('%s')` before using this function", pkg)) } } - chrome.session <- chromote::ChromoteSession$new() - res <- animint2dir(plot.list, open.browser = FALSE, ...) - #Find available port and start server - portNum <- servr::random_port() - normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) - start_servr(serverDirectory = normDir, port = portNum, tmpPath = normDir) - Sys.sleep(3) - url <- sprintf("http://localhost:%d", portNum) - chrome.session$Page$navigate(url) - screenshot_path <- file.path(res$out.dir, "Capture.PNG") - screenshot_full <- file.path(res$out.dir, "Capture_full.PNG") - Sys.sleep(3) - ## Capture screenshot - chrome.session$screenshot(screenshot_full, selector = ".plot_content") - image_raw <- magick::image_read(screenshot_full) - image_trimmed <- magick::image_trim(image_raw) - magick::image_write(image_trimmed, screenshot_path) - unlink(screenshot_full) - chrome.session$close() - # Stop the server - stop_server(normDir) + + if(requireNamespace("chromote") && requireNamespace("magick")) { + chrome.session <- chromote::ChromoteSession$new() + res <- animint2dir(plot.list, open.browser = FALSE, ...) + #Find available port and start server + portNum <- servr::random_port() + normDir <- normalizePath(res$out.dir, winslash = "/", mustWork = TRUE) + start_servr(serverDirectory = normDir, port = portNum, tmpPath = normDir) + Sys.sleep(3) + url <- sprintf("http://localhost:%d", portNum) + chrome.session$Page$navigate(url) + screenshot_path <- file.path(res$out.dir, "Capture.PNG") + screenshot_full <- file.path(res$out.dir, "Capture_full.PNG") + Sys.sleep(3) + ## Capture screenshot + chrome.session$screenshot(screenshot_full, selector = ".plot_content") + image_raw <- magick::image_read(screenshot_full) + image_trimmed <- magick::image_trim(image_raw) + magick::image_write(image_trimmed, screenshot_path) + unlink(screenshot_full) + chrome.session$close() + # Stop the server + stop_server(normDir) + } all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) to_post <- all_files[!(file_info$size == 0 | grepl("~$", all_files))] diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index 604d5da1..65b040ea 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -351,7 +351,6 @@ tests_run <- function(dir = ".", filter = NULL) { #' @seealso \link{tests_run} #' @export tests_exit <- function() { - stop_binary() Sys.unsetenv("ANIMINT_BROWSER") res <- stop_server(tmpPath = find_test_path()) invisible(all(res)) @@ -365,8 +364,7 @@ tests_exit <- function() { #' @param port port number to _attempt_ to run server on. #' @param code R code to execute in a child session #' @return port number of the successful attempt -run_servr <- function(directory = ".", port = 4848, - code = "servr::httd(dir='%s', port=%d)") { +run_servr <- function(directory, port, code) { start_servr(directory, port, code, tmpPath = find_test_path()) } @@ -374,17 +372,6 @@ run_servr <- function(directory = ".", port = 4848, # Functions that are used in multiple places # -------------------------- -stop_binary <- function() { - if (exists("pJS")) pJS$stop() - # these methods are really queries to the server - # thus, if it is already shut down, we get some arcane error message - e <- try({ - remDr$closeWindow() - remDr$closeServer() - }, silent = TRUE) - TRUE -} - # find the path to animint's testthat directory find_test_path <- function(dir = ".") { dir <- normalizePath(dir, winslash = "/", mustWork = TRUE) From 1f7e9334dcbf7f6657006f8deb481e9bdca2adaa Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Thu, 19 Sep 2024 15:22:55 -0400 Subject: [PATCH 41/43] Fix test error --- tests/testthat/helper-functions.R | 4 ++-- tests/testthat/testthat-problems.rds | Bin 0 -> 11708 bytes 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/testthat-problems.rds diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index 65b040ea..12e546e6 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -364,8 +364,8 @@ tests_exit <- function() { #' @param port port number to _attempt_ to run server on. #' @param code R code to execute in a child session #' @return port number of the successful attempt -run_servr <- function(directory, port, code) { - start_servr(directory, port, code, tmpPath = find_test_path()) +run_servr <- function(directory, port) { + start_servr(directory, port, tmpPath = find_test_path()) } # -------------------------- diff --git a/tests/testthat/testthat-problems.rds b/tests/testthat/testthat-problems.rds new file mode 100644 index 0000000000000000000000000000000000000000..368918906288b6165e2bcf8397963d52a988d2f3 GIT binary patch literal 11708 zcmZvCXIN8R(5;kErHKfFKoIE)B1-Q_Q4mnNC=pSS-b7kRq$4OrK&pU%RB0l;M2ZqX zi1bbrvu*I%SahO;%<(>RD-G1jvlPela>rZvCoJ+A|QH zKb>@)%P)7fzWocsut>R|{Hxo=X|I+eClmX(n=QE0#Xum&oAb znV-J~T0iYV)Auawv^HnT%6_K)Sg@g+7n5Nzi|F=0@Bv))*A=Gw?YdITBwwfFQS;$^ zql-y?boeK98`oKxuHCKsXycZ91f9#Cq?kMRM*Ug7%Qu~m8O&1c6x$f&J7rx`O_WW7 zX(~e2{K-N=_ADJP5Y)*;H`M?{4l7 zDvjqYnDl+fc=*pnd`d+r6^-<_wlw^8NO>dq2Ae4$9yIZ{L*Uhiyf3 zad8OX%&#YS?@1%_o(yoLnQ!#Gh*B7QpPyiOOVv?m&woE}q`>>=t=qO7Z^4bmYeQEdGE2kZ z)*ep=x6Y~Ph-At<)60J_9e!VlTUhG?O}T~^Wjh(`^xY9D)QFFdD&415ZH1?)^ALfdCSljr%vb8fB zjIwsKPM1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744yKz2>5x{4K0?+eoF|6Uzy58P`jyN3Tb~&w zdS`-E6}wuSP4)~|+^@DRHi7fQrM%ZCrk&nDtTNS$t}Z`B70dw)4zVKkHHTrZdl!Mi zPop!RO_odUT8Mw}nR}?_SFY&N;aDKtFk6_`RO~5d+}@SbCV0=fyuW@>+w9YBqRgh% sFYm@V(_XrQG4D)O(Esor^1wi@vU4T)Vn^Z#TId|@V0RGKi2LJ#7 literal 0 HcmV?d00001 From f336ee4f873815111300a928e8a6f51faf18ead9 Mon Sep 17 00:00:00 2001 From: siddhesh195 Date: Mon, 30 Sep 2024 02:13:08 +0530 Subject: [PATCH 42/43] removed additional arguments --- R/z_animint.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/z_animint.R b/R/z_animint.R index a7902f6e..b412bd45 100644 --- a/R/z_animint.R +++ b/R/z_animint.R @@ -248,7 +248,7 @@ storeLayer <- function(meta, g, g.data.varied){ #' @example inst/examples/animint2dir.R animint2dir <- function(plot.list, out.dir = NULL, json.file = "plot.json", open.browser = interactive(), - css.file = "", ...) { + css.file = "") { if(is.null(out.dir)){ out.dir <- tempfile() } From 3338cf5ad0236855586245adcf93425dee7a549e Mon Sep 17 00:00:00 2001 From: Siddhesh Deodhar Date: Tue, 8 Oct 2024 22:07:18 -0400 Subject: [PATCH 43/43] Rename stop_server to stop_servr --- NAMESPACE | 2 +- R/utilities.r | 2 +- R/z_pages.R | 2 +- tests/testthat/helper-functions.R | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 00bf0266..0cdd82e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -478,7 +478,7 @@ export(stat_summary_bin) export(stat_summary_hex) export(stat_unique) export(stat_ydensity) -export(stop_server) +export(stop_servr) export(theme) export(theme_animint) export(theme_bw) diff --git a/R/utilities.r b/R/utilities.r index acc4905f..578770fd 100644 --- a/R/utilities.r +++ b/R/utilities.r @@ -292,7 +292,7 @@ start_servr <- function(serverDirectory = ".", port = 4848, system2("Rscript", c("-e", shQuote(cmd)), wait = FALSE) } -stop_server <- function(tmpPath = ".") { +stop_servr <- function(tmpPath = ".") { res <- TRUE f <- file.path(tmpPath, "pids.txt") if (file.exists(f)) { diff --git a/R/z_pages.R b/R/z_pages.R index ee016ee3..43233e24 100644 --- a/R/z_pages.R +++ b/R/z_pages.R @@ -70,7 +70,7 @@ animint2pages <- function(plot.list, github_repo, owner=NULL, commit_message = " unlink(screenshot_full) chrome.session$close() # Stop the server - stop_server(normDir) + stop_servr(normDir) } all_files <- Sys.glob(file.path(res$out.dir, "*")) file_info <- file.info(all_files) diff --git a/tests/testthat/helper-functions.R b/tests/testthat/helper-functions.R index 12e546e6..ae63b3e4 100644 --- a/tests/testthat/helper-functions.R +++ b/tests/testthat/helper-functions.R @@ -352,7 +352,7 @@ tests_run <- function(dir = ".", filter = NULL) { #' @export tests_exit <- function() { Sys.unsetenv("ANIMINT_BROWSER") - res <- stop_server(tmpPath = find_test_path()) + res <- stop_servr(tmpPath = find_test_path()) invisible(all(res)) }