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/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()`. diff --git a/R/fuzzyhelp.R b/R/fuzzyhelp.R index 91d93db..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) { +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.") @@ -15,33 +21,41 @@ 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" + 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)) + 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, helpPort, "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, helpPort, "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, helpPort, "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 @@ -309,7 +323,11 @@ 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, + rstudioServer = FALSE) { method <- match.arg(method) function(input, output) { toc <- create_toc() @@ -341,11 +359,11 @@ 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()) - if (grepl("^http://", content)) { - arguments$src <- content + content <- get_content(reactiveToc(), reactiveSelection(), helpPort, rstudioServer) + 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 + '#'; @@ -389,8 +407,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 +491,9 @@ 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 + rstudioServer <- rstudioapi::isAvailable() && rstudioapi::versionInfo()$mode == "server" + server <- create_server(method, background, helpPort, rstudioServer) # Create new gadget on foreground if (!background) { diff --git a/docs/404.html b/docs/404.html index 042f70e..70d8bdf 100644 --- a/docs/404.html +++ b/docs/404.html @@ -39,7 +39,7 @@ felp - 0.5.0 + 0.5.0.9999 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 447157c..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 99c0b2f..ad76820 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ felp - 0.5.0 + 0.5.0.9999 @@ -51,7 +51,11 @@

Changelog

- + +
+
+
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