From b3bc2e446e05a10868db69d6803cc8e497947160 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 22 Apr 2024 22:51:04 +0900 Subject: [PATCH 1/6] perf(fuzzyhelp): reduce background process from fuzzyhelp --- R/fuzzyhelp.R | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/R/fuzzyhelp.R b/R/fuzzyhelp.R index 91d93db..f1f67a3 100644 --- a/R/fuzzyhelp.R +++ b/R/fuzzyhelp.R @@ -4,7 +4,7 @@ NULL #' Get preview content for Shiny UI #' @noRd -get_content <- function(x, i) { +get_content <- function(x, i, helpPort) { if (NROW(x) == 0L || length(i) == 0L) { return("") } @@ -15,7 +15,6 @@ get_content <- function(x, i) { type <- x$Type[i] topic <- x$Topic[i] package <- x$Package[i] - helpPort <- startDynamicHelp() helpUrl <- "http://127.0.0.1:%d/%s/%s/%s/%s%s" if (type == "help") { @@ -309,7 +308,7 @@ parse_query <- function(string) { queries[queries != ""] } -create_server <- function(method = c("fzf", "lv"), background = FALSE) { +create_server <- function(method = c("fzf", "lv"), background = FALSE, helpPort = NULL) { method <- match.arg(method) function(input, output) { toc <- create_toc() @@ -341,7 +340,7 @@ create_server <- function(method = c("fzf", "lv"), background = FALSE) { }) reactiveHelp <- shiny::reactive({ arguments <- list(style = "width: 100%; height: 100%;", id = "helpViewer") - content <- get_content(reactiveToc(), reactiveSelection()) + content <- get_content(reactiveToc(), reactiveSelection(), helpPort) if (grepl("^http://", content)) { arguments$src <- content } else { @@ -389,8 +388,13 @@ create_server <- function(method = c("fzf", "lv"), background = FALSE) { } .env <- new.env() +# 31537 + +startDynamicHelp <- function(background) { + if (background) { + return(tools::startDynamicHelp(NA)) + } -startDynamicHelp <- function() { if ( !is.null(.env$helpProcess) && is.null(.env$helpProcess$get_exit_status()) && @@ -468,7 +472,8 @@ fuzzyhelp <- function( background = getOption("fuzzyhelp.background", TRUE), viewer = shiny::paneViewer()) { app <- create_ui(query, background) - server <- create_server(method, background) + helpPort <- startDynamicHelp(background) # NOTE: eager evaluate + server <- create_server(method, background, helpPort) # Create new gadget on foreground if (!background) { From 1054173145aa8648760b9c49605c51bfeff62543 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:02:27 +0900 Subject: [PATCH 2/6] fix(fuzzyhelp): not working on RStudio Server --- R/fuzzyhelp.R | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/R/fuzzyhelp.R b/R/fuzzyhelp.R index f1f67a3..2a17790 100644 --- a/R/fuzzyhelp.R +++ b/R/fuzzyhelp.R @@ -4,7 +4,7 @@ NULL #' Get preview content for Shiny UI #' @noRd -get_content <- function(x, i, helpPort) { +get_content <- function(x, i, helpPort, rstudioServer) { if (NROW(x) == 0L || length(i) == 0L) { return("") } @@ -15,14 +15,18 @@ get_content <- function(x, i, helpPort) { type <- x$Type[i] topic <- x$Topic[i] package <- x$Package[i] - helpUrl <- "http://127.0.0.1:%d/%s/%s/%s/%s%s" + helpUrl <- if (rstudioServer) { + "/help/%s/%s/%s/%s%s" + } else { + paste0("http://127.0.0.1:", helpPort, "/%s/%s/%s/%s%s") + } if (type == "help") { if (is.null(helpPort)) { return(get_help(topic, package)) } h <- help((topic), (package), help_type = "html") - return(sprintf(helpUrl, helpPort, "library", package, "html", basename(h), ".html")) + return(sprintf(helpUrl, "library", package, "html", basename(h), ".html")) } if (type == "vignette") { @@ -30,14 +34,14 @@ get_content <- function(x, i, helpPort) { return(get_vignette(topic, package)) } v <- utils::vignette(topic, package) - return(sprintf(helpUrl, helpPort, "library", basename(v$Dir), "doc", v$PDF, "")) + return(sprintf(helpUrl, "library", basename(v$Dir), "doc", v$PDF, "")) } if (type == "demo") { if (is.null(helpPort)) { return(sprintf('Call demo("%s", "%s") to see demo', topic, package)) } - return(sprintf(helpUrl, helpPort, "library", package, "Demo", topic, "")) + return(sprintf(helpUrl, "library", package, "Demo", topic, "")) } paste("Viewer not available for the type:", type) @@ -308,7 +312,11 @@ parse_query <- function(string) { queries[queries != ""] } -create_server <- function(method = c("fzf", "lv"), background = FALSE, helpPort = NULL) { +create_server <- function( + method = c("fzf", "lv"), + background = FALSE, + helpPort = NULL, + rstudioServer = FALSE) { method <- match.arg(method) function(input, output) { toc <- create_toc() @@ -340,8 +348,8 @@ create_server <- function(method = c("fzf", "lv"), background = FALSE, helpPort }) reactiveHelp <- shiny::reactive({ arguments <- list(style = "width: 100%; height: 100%;", id = "helpViewer") - content <- get_content(reactiveToc(), reactiveSelection(), helpPort) - if (grepl("^http://", content)) { + content <- get_content(reactiveToc(), reactiveSelection(), helpPort, rstudioServer) + if (grepl("^http[s]?://", content) || (rstudioServer && grepl("^/help/", content))) { arguments$src <- content } else { arguments$srcdoc <- content @@ -473,7 +481,8 @@ fuzzyhelp <- function( viewer = shiny::paneViewer()) { app <- create_ui(query, background) helpPort <- startDynamicHelp(background) # NOTE: eager evaluate - server <- create_server(method, background, helpPort) + rstudioServer <- rstudioapi::isAvailable() && rstudioapi::versionInfo()$mode == "server" + server <- create_server(method, background, helpPort, rstudioServer) # Create new gadget on foreground if (!background) { From 41a7c5eecd10c733d396b9f2073458dc4ec55d37 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:19:50 +0900 Subject: [PATCH 3/6] docs(NEWS): Fixed `fuzzyhelp()` not showing preview on RStudio Server. --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 60c5a5f..c5b5e3c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# felp 0.5.1 + +- Fixed `fuzzyhelp()` not showing preview on RStudio Server. + # felp 0.5.0 - On `fuzzyhelp()`, help/vignette contents gain syntax highlights and links. It formerly used `Rd2HTML()` to generate HTML contents. Now the contents inherit from a help server with `startDynamicHelp()`, which means they are exactly same as the contents of `help()` or `vignette()`. From dab30b32e305b356620f5741cc9b6761a607a894 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:20:52 +0900 Subject: [PATCH 4/6] chore(DESCRIPTION): be v0.5.0.9999 --- DESCRIPTION | 2 +- docs/articles/felp.html | 2 +- docs/news/index.html | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index de0338f..e0a3382 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: felp Type: Package Title: Functional Help for Functions, Objects, and Packages -Version: 0.5.0 +Version: 0.5.0.9999 Author: Atsushi Yasumoto [aut, cph, cre] () Authors@R: c( person( diff --git a/docs/articles/felp.html b/docs/articles/felp.html index 447157c..c284e8b 100644 --- a/docs/articles/felp.html +++ b/docs/articles/felp.html @@ -323,7 +323,7 @@

felp(package) - +

+ +
+
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 0d08bbe..7106df4 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 7cb7a19..bd91ce5 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/articles/felp.html b/docs/articles/felp.html index c284e8b..9e5884b 100644 --- a/docs/articles/felp.html +++ b/docs/articles/felp.html @@ -40,7 +40,7 @@ felp - 0.5.0 + 0.5.0.9999 @@ -295,7 +295,7 @@

felp(package)felp(package) felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/authors.html b/docs/authors.html index e6941a8..e3e2e36 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 @@ -66,13 +66,13 @@

Citation

Yasumoto A (2024). felp: Functional Help for Functions, Objects, and Packages. -R package version 0.5.0, https://github.com/atusy/felp. +R package version 0.5.0.9999, https://github.com/atusy/felp.

@Manual{,
   title = {felp: Functional Help for Functions, Objects, and Packages},
   author = {Atsushi Yasumoto},
   year = {2024},
-  note = {R package version 0.5.0},
+  note = {R package version 0.5.0.9999},
   url = {https://github.com/atusy/felp},
 }
diff --git a/docs/index.html b/docs/index.html index 1c00e81..ad86067 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/news/index.html b/docs/news/index.html index 63a5005..ad76820 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 9c25089..abb2171 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,5 +3,5 @@ pkgdown: 2.0.7 pkgdown_sha: ~ articles: felp: felp.html -last_built: 2024-04-18T14:16Z +last_built: 2024-04-22T14:20Z diff --git a/docs/reference/dummy.html b/docs/reference/dummy.html index f68aba4..39f3d0e 100644 --- a/docs/reference/dummy.html +++ b/docs/reference/dummy.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/reference/felp.html b/docs/reference/felp.html index dc34a65..313181d 100644 --- a/docs/reference/felp.html +++ b/docs/reference/felp.html @@ -18,7 +18,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/reference/fuzzyhelp.html b/docs/reference/fuzzyhelp.html index deb33f6..d45b082 100644 --- a/docs/reference/fuzzyhelp.html +++ b/docs/reference/fuzzyhelp.html @@ -23,7 +23,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/reference/index.html b/docs/reference/index.html index 691d923..a3e792a 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 diff --git a/docs/reference/question.html b/docs/reference/question.html index dbe9832..211c689 100644 --- a/docs/reference/question.html +++ b/docs/reference/question.html @@ -20,7 +20,7 @@ felp - 0.5.0 + 0.5.0.9999 From 848acc20dec211de91d3d8a1415bed941c64ba91 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:47:56 +0900 Subject: [PATCH 6/6] refactor(fuzzyhelp): change return value of an internal function to simplify logic --- R/fuzzyhelp.R | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/R/fuzzyhelp.R b/R/fuzzyhelp.R index 2a17790..bcd4bb3 100644 --- a/R/fuzzyhelp.R +++ b/R/fuzzyhelp.R @@ -3,10 +3,16 @@ NULL #' Get preview content for Shiny UI +#' +#' @value `list(src?: character, srcdoc?: character)` +#' `src` and `srcdoc` are exclusive. If dynamic help server is available, +#' `src` returns address to the help page. Otherwise, `srcdoc` returns +#' HTML content of the help page. +#' #' @noRd get_content <- function(x, i, helpPort, rstudioServer) { if (NROW(x) == 0L || length(i) == 0L) { - return("") + return(list(srcdoc = "")) } if (length(i) > 1L) { warning("i should be an integer vector of the length equal to 1.") @@ -23,28 +29,33 @@ get_content <- function(x, i, helpPort, rstudioServer) { if (type == "help") { if (is.null(helpPort)) { - return(get_help(topic, package)) + return(list(srcdoc = if (is.null(helpPort)) get_help(topic, package))) + } else { + h <- help((topic), (package), help_type = "html") + return( + list(src = sprintf(helpUrl, "library", package, "html", basename(h), ".html")) + ) } - h <- help((topic), (package), help_type = "html") - return(sprintf(helpUrl, "library", package, "html", basename(h), ".html")) } if (type == "vignette") { if (is.null(helpPort)) { - return(get_vignette(topic, package)) + return(list(srcdoc = if (is.null(helpPort)) get_vignette(topic, package))) + } else { + v <- utils::vignette(topic, package) + return(list(src = sprintf(helpUrl, "library", basename(v$Dir), "doc", v$PDF, ""))) } - v <- utils::vignette(topic, package) - return(sprintf(helpUrl, "library", basename(v$Dir), "doc", v$PDF, "")) } if (type == "demo") { if (is.null(helpPort)) { - return(sprintf('Call demo("%s", "%s") to see demo', topic, package)) + return(list(srcdoc = sprintf('Call demo("%s", "%s") to see demo', topic, package))) + } else { + return(list(src = sprintf(helpUrl, "library", package, "Demo", topic, ""))) } - return(sprintf(helpUrl, "library", package, "Demo", topic, "")) } - paste("Viewer not available for the type:", type) + return(list(srcdoc = paste("Viewer not available for the type:", type))) } #' Create ToC of help @@ -349,10 +360,10 @@ create_server <- function( reactiveHelp <- shiny::reactive({ arguments <- list(style = "width: 100%; height: 100%;", id = "helpViewer") content <- get_content(reactiveToc(), reactiveSelection(), helpPort, rstudioServer) - if (grepl("^http[s]?://", content) || (rstudioServer && grepl("^/help/", content))) { - arguments$src <- content + if (is.null(content$srcdoc)) { + arguments$src <- content$src } else { - arguments$srcdoc <- content + arguments$srcdoc <- content$srcdoc arguments$onload <- "(function(){ // replace anchors to avoid nesting shiny widgets const pattern = document.baseURI + '#';