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] (fuzzyhelp()
not showing preview on RStudio Server.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()
.fuzzyhelp()
, demo contents can be previewed.fuzzyhelp(background = FALSE)
, “Done” and “Cancel” buttons are removed because the feature of the “Done” requires the Shiny app run on the main thread.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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 + '#';