From d6a479fd83f4c2de343a20928f99bab14c6a3764 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:37:49 +0900 Subject: [PATCH] fix(fuzzyhelp): broken addin --- R/fuzzyhelp.R | 21 ++++++++++++++++----- inst/rstudio/addins.dcf | 2 +- man/fuzzyhelp.Rd | 7 ++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/R/fuzzyhelp.R b/R/fuzzyhelp.R index d68fd58..706560c 100644 --- a/R/fuzzyhelp.R +++ b/R/fuzzyhelp.R @@ -379,6 +379,7 @@ create_server <- function(method = c("fzf", "lv")) { #' @param background Whether to run a shiny gadget in a background process. #' The default value is `TRUE` and can be changed by #' `option(fuzzyhelp.background = FALSE)`. +#' @inheritParams shiny::runGadget #' #' @note #' The default fuzzy match algorithm is a simplified version of @@ -397,13 +398,14 @@ create_server <- function(method = c("fzf", "lv")) { fuzzyhelp <- function( query = "", method = getOption("fuzzyhelp.method", "fzf"), - background = getOption("fuzzyhelp.background", TRUE)) { + background = getOption("fuzzyhelp.background", TRUE), + viewer = shiny::paneViewer()) { app <- create_ui(query) server <- create_server(method) # Create new gadget on foreground if (!background) { - shiny::runGadget(app, server) + shiny::runGadget(app, server, viewer = viewer) return(invisible(NULL)) } @@ -427,17 +429,26 @@ fuzzyhelp <- function( # Create new gadget on background .env$fuzzyhelp <- callr::r_bg( - function(..., .env) { + function(..., .env, base_viewer) { viewer <- function(url) { writeLines(url, .env$fuzzyhelp_url) - shiny::paneViewer()(url) + base_viewer(url) } shiny::runGadget(..., viewer = viewer) }, - args = list(app = app, server = server, .env = .env), + args = list(app = app, server = server, .env = .env, base_viewer = viewer), env = Sys.getenv(), package = TRUE ) return(.env$fuzzyhelp) } + +fuzzyhelp_addin <- function() { + script <- tempfile() + writeLines( + "felp::fuzzyhelp(background = FALSE, viewer = rstudioapi::viewer)", + script + ) + rstudioapi::jobRunScript(script, name = "fuzzyhelp") +} diff --git a/inst/rstudio/addins.dcf b/inst/rstudio/addins.dcf index 07e5654..010349f 100644 --- a/inst/rstudio/addins.dcf +++ b/inst/rstudio/addins.dcf @@ -1,4 +1,4 @@ Name: Fuzzy Search on R Help Description: Search and view help files with fuzzy queries. -Binding: fuzzyhelp +Binding: fuzzyhelp_addin Interactive: true diff --git a/man/fuzzyhelp.Rd b/man/fuzzyhelp.Rd index 37fcf87..74cc6ff 100644 --- a/man/fuzzyhelp.Rd +++ b/man/fuzzyhelp.Rd @@ -7,7 +7,8 @@ fuzzyhelp( query = "", method = getOption("fuzzyhelp.method", "fzf"), - background = getOption("fuzzyhelp.background", TRUE) + background = getOption("fuzzyhelp.background", TRUE), + viewer = shiny::paneViewer() ) } \arguments{ @@ -20,6 +21,10 @@ default value can be tweaked by \code{options(fuzzyhelp.method = "lv")}.} \item{background}{Whether to run a shiny gadget in a background process. The default value is \code{TRUE} and can be changed by \code{option(fuzzyhelp.background = FALSE)}.} + +\item{viewer}{Specify where the gadget should be displayed--viewer pane, +dialog window, or external browser--by passing in a call to one of the +\code{\link[shiny:viewer]{viewer()}} functions.} } \description{ Users no more have to afraid of exact name of the object they need help.