mirror of
https://github.com/rstudio/shiny.git
synced 2026-02-06 20:55:24 -05:00
Allow modules to exclude their inputs
This commit is contained in:
@@ -500,19 +500,25 @@ urlModal <- function(url, title = "Bookmarked application link", subtitle = NULL
|
||||
)
|
||||
}
|
||||
|
||||
#' Configure bookmarking for a Shiny application
|
||||
#' Enable bookmarking for a Shiny application
|
||||
#'
|
||||
#' @param store Either \code{"url"}, which encodes all of the relevant values in
|
||||
#' a URL, \code{"server"}, which saves to disk on the server, or
|
||||
#' \code{"disable"}, which disables any previously-enabled bookmarking.
|
||||
#' @param exclude A character vector of names of input values to exclude from
|
||||
#' @export
|
||||
enableBookmarking <- function(store = c("url", "server", "disable")) {
|
||||
store <- match.arg(store)
|
||||
shinyOptions(bookmarkStore = store)
|
||||
}
|
||||
|
||||
|
||||
#' Exclude inputs from bookmarking
|
||||
#'
|
||||
#' @param names A character vector containing names of inputs to exclude from
|
||||
#' bookmarking.
|
||||
#' @export
|
||||
configureBookmarking <- function(store = c("url", "server", "disable"),
|
||||
exclude = NULL)
|
||||
{
|
||||
store <- match.arg(store)
|
||||
shinyOptions(bookmarkStore = store, bookmarkExclude = exclude)
|
||||
setBookmarkExclude <- function(names = character(0), session = getDefaultReactiveDomain()) {
|
||||
session$setBookmarkExclude(names)
|
||||
}
|
||||
|
||||
|
||||
@@ -565,11 +571,10 @@ onRestored <- function(fun, session = getDefaultReactiveDomain()) {
|
||||
consumeBookmarkOptions <- function() {
|
||||
# Get options from configureBookmarking
|
||||
options <- list(
|
||||
bookmarkStore = getShinyOption("bookmarkStore"),
|
||||
bookmarkExclude = getShinyOption("bookmarkExclude")
|
||||
bookmarkStore = getShinyOption("bookmarkStore")
|
||||
)
|
||||
|
||||
shinyOptions(bookmarkStore = NULL, bookmarkExclude = NULL)
|
||||
shinyOptions(bookmarkStore = NULL)
|
||||
|
||||
options
|
||||
}
|
||||
|
||||
24
R/shiny.R
24
R/shiny.R
@@ -359,6 +359,7 @@ ShinySession <- R6Class(
|
||||
bookmarkedCallbacks = 'Callbacks',
|
||||
restoreCallbacks = 'Callbacks',
|
||||
restoredCallbacks = 'Callbacks',
|
||||
bookmarkExclude = character(0), # Names of inputs to exclude from bookmarking
|
||||
|
||||
sendResponse = function(requestMsg, value) {
|
||||
if (is.null(requestMsg$tag)) {
|
||||
@@ -435,7 +436,6 @@ ShinySession <- R6Class(
|
||||
# Get bookmarking config
|
||||
appConfig <- getShinyOption("appConfig")
|
||||
store <- appConfig$bookmarkStore %OR% "disable"
|
||||
exclude <- appConfig$bookmarkExclude
|
||||
|
||||
if (store == "disable")
|
||||
return()
|
||||
@@ -453,7 +453,7 @@ ShinySession <- R6Class(
|
||||
withLogErrors({
|
||||
saveState <- ShinySaveState$new(
|
||||
input = session$input,
|
||||
exclude = exclude,
|
||||
exclude = session$getBookmarkExclude(),
|
||||
onSave = function(state) {
|
||||
private$bookmarkCallbacks$invoke(state)
|
||||
}
|
||||
@@ -643,6 +643,11 @@ ShinySession <- R6Class(
|
||||
makeScope = function(namespace) {
|
||||
ns <- NS(namespace)
|
||||
|
||||
# Names of inputs to exclude from bookmarking. Can't be part of the scope
|
||||
# object because `$<-.session_proxy` doesn't allow assignment on overidden
|
||||
# names.
|
||||
bookmarkExclude = character(0)
|
||||
|
||||
scope <- createSessionProxy(self,
|
||||
input = .createReactiveValues(private$.input, readonly = TRUE, ns = ns),
|
||||
output = .createOutputWriter(self, ns = ns),
|
||||
@@ -657,10 +662,15 @@ ShinySession <- R6Class(
|
||||
self$makeScope(ns(namespace))
|
||||
},
|
||||
|
||||
setBookmarkExclude = function(names) {
|
||||
bookmarkExclude <<- names
|
||||
},
|
||||
getBookmarkExclude = function() {
|
||||
bookmarkExclude
|
||||
},
|
||||
onBookmark = function(fun) {
|
||||
self$onBookmark(function(state) {
|
||||
# TODO: Update `exclude` to have per-session values.
|
||||
scopeState <- ShinySaveState$new(scope$input)
|
||||
scopeState <- ShinySaveState$new(scope$input, scope$getBookmarkExclude())
|
||||
|
||||
# Create subdir for this scope
|
||||
if (!is.null(state$dir)) {
|
||||
@@ -1033,6 +1043,12 @@ ShinySession <- R6Class(
|
||||
}
|
||||
},
|
||||
|
||||
setBookmarkExclude = function(names) {
|
||||
private$bookmarkExclude <- names
|
||||
},
|
||||
getBookmarkExclude = function() {
|
||||
private$bookmarkExclude
|
||||
},
|
||||
onBookmark = function(fun) {
|
||||
if (!is.function(fun) || length(fun) != 1) {
|
||||
stop("`fun` must be a function that takes one argument")
|
||||
|
||||
Reference in New Issue
Block a user