Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit of bookmark script for bookmark include instead of exc… #69

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions R/bookmark.R
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 31 in R/bookmark.R

View check run for this annotation

Codecov / codecov/patch

R/bookmark.R#L31

Added line #L31 was not covered by tests
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

# print to log for testing
# print(paste("ExcludedIDs:", paste(toExclude, collapse = ", ")))
Fixed Show fixed Hide fixed

# exclude all remaining inputs from bookmark
setBookmarkExclude(toExclude)

Check warning on line 37 in R/bookmark.R

View check run for this annotation

Codecov / codecov/patch

R/bookmark.R#L37

Added line #L37 was not covered by tests
Fixed Show fixed Hide fixed

Check warning

Code scanning / lintr

no visible global function definition for 'setBookmarkExclude' Warning

no visible global function definition for 'setBookmarkExclude'

Check warning

Code scanning / lintr

no visible binding for global variable 'toExclude' Warning

no visible binding for global variable 'toExclude'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've switched from to_exclude to toExclude here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you call functions explicitly, so in this case shiny::setBookmarkExclude(...)


print("bookmarked")

Check warning on line 39 in R/bookmark.R

View check run for this annotation

Codecov / codecov/patch

R/bookmark.R#L39

Added line #L39 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use message(), warning() etc rather than print() wherever possible

# Trigger bookmarking whenever relevant inputs change
session$doBookmark()

Check warning on line 41 in R/bookmark.R

View check run for this annotation

Codecov / codecov/patch

R/bookmark.R#L41

Added line #L41 was not covered by tests

Check warning

Code scanning / lintr

no visible binding for global variable 'session' Warning

no visible binding for global variable 'session'
}
Loading