From 7648d74e4d685fc48cab85bbeb1bac0c8856f756 Mon Sep 17 00:00:00 2001 From: alex-rogers-hub Date: Thu, 12 Dec 2024 10:42:25 +0000 Subject: [PATCH 1/3] initial commit of bookmark script for bookmark include instead of exclude --- R/bookmark.R | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 R/bookmark.R diff --git a/R/bookmark.R b/R/bookmark.R new file mode 100644 index 0000000..e00bd1c --- /dev/null +++ b/R/bookmark.R @@ -0,0 +1,42 @@ +#' DfE bookmark include +#' +#' @description +#' This function allows for a whitelist of included inputs +#' for bookmarking +#' +#' @param bookmarkingWhitelist list of inputs to include in bookmark +#' @return a bookmark with relevant inputs included +#' +#' @export +#' @examples +#' # You will need a line such as this in your global.R script ================ +#' bookmarkingWhitelist <- c("navlistPanel", "tabsetpanels") +#' +#' # In the server.R script =================================================== +#' shiny::observe({ +#' setBookmarkInclude(bookmarkingWhitelist) +#' }) +#' +#' observe({ +#' # Trigger this observer every time an input changes +#' reactiveValuesToList(input) +#' session$doBookmark() +#' }) +#' +#' onBookmarked(function(url) { +#' updateQueryString(url) +#' }) +setBookmarkInclude <- function(bookmarkingWhitelist){ + # exclude the white list from complete list + toExclude <- setdiff(names(input), bookmarkingWhitelist) + + # print to log for testing + # print(paste("ExcludedIDs:", paste(toExclude, collapse = ", "))) + + # exclude all remaining inputs from bookmark + setBookmarkExclude(toExclude) + + print('bookmarked') + # Trigger bookmarking whenever relevant inputs change + session$doBookmark() +} From 850b990b5dcf9bb0ee3dd66fba04c497c7482f7f Mon Sep 17 00:00:00 2001 From: alex-rogers-hub Date: Mon, 16 Dec 2024 13:48:13 +0000 Subject: [PATCH 2/3] style edits --- R/bookmark.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/bookmark.R b/R/bookmark.R index e00bd1c..55597aa 100644 --- a/R/bookmark.R +++ b/R/bookmark.R @@ -18,15 +18,15 @@ #' }) #' #' observe({ -#' # Trigger this observer every time an input changes +#' # Trigger this observer every time an input changes #' reactiveValuesToList(input) #' session$doBookmark() -#' }) +#' }) #' #' onBookmarked(function(url) { -#' updateQueryString(url) -#' }) -setBookmarkInclude <- function(bookmarkingWhitelist){ +#' updateQueryString(url) +#' }) +setBookmarkInclude <- function(bookmarkingWhitelist) { # exclude the white list from complete list toExclude <- setdiff(names(input), bookmarkingWhitelist) @@ -36,7 +36,7 @@ setBookmarkInclude <- function(bookmarkingWhitelist){ # exclude all remaining inputs from bookmark setBookmarkExclude(toExclude) - print('bookmarked') + print("bookmarked") # Trigger bookmarking whenever relevant inputs change session$doBookmark() } From c1732b1fee9dfefe91299f6972a13b56d7517c27 Mon Sep 17 00:00:00 2001 From: alex-rogers-hub Date: Mon, 16 Dec 2024 14:50:29 +0000 Subject: [PATCH 3/3] lintr fix --- R/bookmark.R | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/R/bookmark.R b/R/bookmark.R index 55597aa..45b012c 100644 --- a/R/bookmark.R +++ b/R/bookmark.R @@ -10,11 +10,11 @@ #' @export #' @examples #' # You will need a line such as this in your global.R script ================ -#' bookmarkingWhitelist <- c("navlistPanel", "tabsetpanels") +#' bookmarking_whitelist <- c("navlistPanel", "tabsetpanels") #' #' # In the server.R script =================================================== #' shiny::observe({ -#' setBookmarkInclude(bookmarkingWhitelist) +#' set_bookmark_include(bookmarking_whitelist) #' }) #' #' observe({ @@ -26,12 +26,9 @@ #' onBookmarked(function(url) { #' updateQueryString(url) #' }) -setBookmarkInclude <- function(bookmarkingWhitelist) { +set_bookmark_include <- function(bookmarking_whitelist) { # exclude the white list from complete list - toExclude <- setdiff(names(input), bookmarkingWhitelist) - - # print to log for testing - # print(paste("ExcludedIDs:", paste(toExclude, collapse = ", "))) + to_exclude <- setdiff(names(input), bookmarking_whitelist) # exclude all remaining inputs from bookmark setBookmarkExclude(toExclude)