mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Unset shinyOptions when set to NULL
This commit is contained in:
@@ -40,7 +40,7 @@ shinyOptions <- function(...) {
|
||||
newOpts <- list(...)
|
||||
|
||||
if (length(newOpts) > 0) {
|
||||
.globals$options <- mergeVectors(.globals$options, newOpts)
|
||||
.globals$options <- dropNulls(mergeVectors(.globals$options, newOpts))
|
||||
invisible(.globals$options)
|
||||
} else {
|
||||
.globals$options
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
context("options")
|
||||
|
||||
sortByName <- function(x) {
|
||||
if (anyUnnamed(x))
|
||||
stop("Can't sort by name because there are unnamed items")
|
||||
|
||||
if (any(duplicated(names(x))))
|
||||
stop("Can't sort by name because there are duplicate names")
|
||||
|
||||
x[sort(names(x))]
|
||||
}
|
||||
|
||||
test_that("Local options", {
|
||||
# Basic options
|
||||
shinyOptions(a = 1, b = 2)
|
||||
|
||||
expect_identical(sortByName(shinyOptions()), sortByName(list(a = 1, b = 2)))
|
||||
expect_true(contents_identical(shinyOptions(),list(a = 1, b = 2)))
|
||||
expect_identical(getShinyOption('a'), 1)
|
||||
expect_identical(getShinyOption('b'), 2)
|
||||
|
||||
@@ -24,13 +14,13 @@ test_that("Local options", {
|
||||
|
||||
withLocalOptions({
|
||||
# No changes yet
|
||||
expect_identical(sortByName(shinyOptions()), sortByName(list(a = 1, b = 2)))
|
||||
expect_true(contents_identical(shinyOptions(), list(a = 1, b = 2)))
|
||||
expect_identical(getShinyOption('a'), 1)
|
||||
expect_identical(getShinyOption('b'), 2)
|
||||
|
||||
# Override an option
|
||||
shinyOptions(a = 3)
|
||||
expect_identical(sortByName(shinyOptions()), sortByName(list(b = 2, a = 3)))
|
||||
expect_true(contents_identical(shinyOptions(), list(b = 2, a = 3)))
|
||||
expect_identical(getShinyOption('a'), 3)
|
||||
expect_identical(getShinyOption('b'), 2)
|
||||
|
||||
@@ -42,14 +32,22 @@ test_that("Local options", {
|
||||
withLocalOptions({
|
||||
# Override an option
|
||||
shinyOptions(a = 4)
|
||||
expect_identical(sortByName(shinyOptions()), sortByName(list(b = 2, a = 4)))
|
||||
expect_true(contents_identical(shinyOptions(), list(b = 2, a = 4)))
|
||||
expect_identical(getShinyOption('a'), 4)
|
||||
expect_identical(getShinyOption('b'), 2)
|
||||
})
|
||||
})
|
||||
|
||||
# Should be back to original state
|
||||
expect_identical(shinyOptions(), list(a = 1, b = 2))
|
||||
expect_true(contents_identical(shinyOptions(), list(a = 1, b = 2)))
|
||||
expect_identical(getShinyOption('a'), 1)
|
||||
expect_identical(getShinyOption('b'), 2)
|
||||
|
||||
# Setting options to NULL removes them entirely
|
||||
shinyOptions(b = NULL)
|
||||
expect_identical(shinyOptions(), list(a = 1))
|
||||
|
||||
|
||||
# Finish tests; reset shinyOptions
|
||||
shinyOptions(a = NULL)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user