Skip to content

Commit cfecee3

Browse files
committed
Record help addin use
1 parent 511961e commit cfecee3

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Authors@R: c(
1111
email = "guyliann.engels@umons.ac.be"))
1212
Maintainer: Philippe Grosjean <phgrosjean@sciviews.org>
1313
Depends: R (>= 4.2.0)
14-
Imports: learnitdown, gert, rstudioapi, shiny, miniUI, shinyAce, methods, utils, svMisc
14+
Imports: learnitdown, gert, rstudioapi, shiny, miniUI, shinyAce, methods, utils, svMisc, httr2
1515
Suggests:
1616
covr,
1717
knitr,

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export(sign_out)
1010
export(switch_repo)
1111
importFrom(gert,git_remote_info)
1212
importFrom(gert,git_remote_set_url)
13+
importFrom(httr2,req_body_json)
14+
importFrom(httr2,req_headers)
15+
importFrom(httr2,req_perform)
16+
importFrom(httr2,request)
1317
importFrom(methods,findFunction)
1418
importFrom(miniUI,gadgetTitleBar)
1519
importFrom(miniUI,miniButtonBlock)

R/addins.R

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ switch_repo_addin <- function()
3636
#' @importFrom svMisc assign_temp get_temp
3737
#' @importFrom rstudioapi sendToConsole
3838
#' @importFrom utils ? methods
39+
#' @importFrom httr2 request req_body_json req_headers req_perform
3940
.sdd_help_addin <- function() {
4041

4142
get_help <- function(message) {
@@ -108,12 +109,17 @@ switch_repo_addin <- function()
108109
l <- length(fun_env_names)
109110
if (!l) {# Function not found
110111
# Ask help system directly
111-
cmd <- parse(text = paste0("?", cur_fun))
112-
if (length(eval(cmd))) {# Help page found
113-
fun <- cur_fun
114-
ns <- "" # Unknown
115-
alt_fun_msg <- ""
116-
} else {# Not found
112+
if (cur_fun != "") {
113+
cmd <- parse(text = paste0("?", cur_fun))
114+
if (length(eval(cmd))) {# Help page found
115+
fun <- cur_fun
116+
ns <- "" # Unknown
117+
alt_fun_msg <- ""
118+
} else {# Not found
119+
fun <- ""
120+
ns <- ""
121+
}
122+
} else {# No function?
117123
fun <- ""
118124
ns <- ""
119125
}
@@ -396,6 +402,26 @@ switch_repo_addin <- function()
396402
#message(help_code)
397403
rstudioapi::sendToConsole(help_code, execute = TRUE, echo = TRUE,
398404
focus = FALSE)
405+
406+
# If help page (not chatbot), record the data in the database
407+
if (context$engine == "SciViews Chatbot")
408+
return(invisible(help_code))
409+
410+
chat_url <- getOption("SciViews.chatbot.url",
411+
Sys.getenv("SCIVIEWS_CHATBOT_URL", ""))
412+
api_key <- Sys.getenv("CONNECT_API_KEY", "")
413+
if (chat_url != "" && api_key != "") {
414+
help_url <- paste0(dirname(chat_url), "/help")
415+
request <- httr2::request(help_url) |>
416+
httr2::req_headers("Accept" = "application/json",
417+
"Authorization" = paste("Key", api_key))
418+
context$code <- help_code
419+
request <- request |>
420+
httr2::req_body_json(context)
421+
res <- try(httr2::req_perform(request), silent = TRUE)
422+
svMisc::assign_temp("sdd_help_result", res, replace.existing = TRUE)
423+
}
424+
399425
invisible(help_code)
400426
}
401427

0 commit comments

Comments
 (0)