mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-11 07:58:11 -05:00
Compare commits
4 Commits
rc-v1.12.1
...
set_app_st
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2be21861f | ||
|
|
fce5216000 | ||
|
|
e418f3540a | ||
|
|
977383de7f |
@@ -7,6 +7,17 @@ NULL
|
||||
|
||||
.globals$appState <- NULL
|
||||
|
||||
#' Check whether a Shiny application is running
|
||||
#'
|
||||
#' This function tests whether a Shiny application is currently running.
|
||||
#'
|
||||
#' @return `TRUE` if a Shiny application is currently running. Otherwise,
|
||||
#' `FALSE`.
|
||||
#' @export
|
||||
isRunning <- function() {
|
||||
!is.null(getCurrentAppState())
|
||||
}
|
||||
|
||||
initCurrentAppState <- function(appobj) {
|
||||
if (!is.null(.globals$appState)) {
|
||||
stop("Can't initialize current app state when another is currently active.")
|
||||
@@ -21,6 +32,14 @@ getCurrentAppState <- function() {
|
||||
.globals$appState
|
||||
}
|
||||
|
||||
getCurrentAppStateOptions <- function() {
|
||||
.globals$appState$options
|
||||
}
|
||||
setCurrentAppStateOptions <- function(options) {
|
||||
stopifnot(isRunning())
|
||||
.globals$appState$options <- options
|
||||
}
|
||||
|
||||
clearCurrentAppState <- function() {
|
||||
.globals$appState <- NULL
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ MockShinySession <- R6Class(
|
||||
self$token <- createUniqueId(16)
|
||||
|
||||
# Copy app-level options
|
||||
self$options <- getCurrentAppState()$options
|
||||
self$options <- getCurrentAppStateOptions()
|
||||
|
||||
self$cache <- cachem::cache_mem()
|
||||
self$appcache <- cachem::cache_mem()
|
||||
|
||||
10
R/server.R
10
R/server.R
@@ -495,16 +495,6 @@ serviceApp <- function() {
|
||||
|
||||
.shinyServerMinVersion <- '0.3.4'
|
||||
|
||||
#' Check whether a Shiny application is running
|
||||
#'
|
||||
#' This function tests whether a Shiny application is currently running.
|
||||
#'
|
||||
#' @return `TRUE` if a Shiny application is currently running. Otherwise,
|
||||
#' `FALSE`.
|
||||
#' @export
|
||||
isRunning <- function() {
|
||||
!is.null(getCurrentAppState())
|
||||
}
|
||||
|
||||
|
||||
# Returns TRUE if we're running in Shiny Server or other hosting environment,
|
||||
|
||||
@@ -19,10 +19,10 @@ getShinyOption <- function(name, default = NULL) {
|
||||
}
|
||||
|
||||
# Check if there's a current app
|
||||
app_state <- getCurrentAppState()
|
||||
if (!is.null(app_state)) {
|
||||
if (name %in% names(app_state$options)) {
|
||||
return(app_state$options[[name]])
|
||||
if (isRunning()) {
|
||||
app_state_options <- getCurrentAppStateOptions()
|
||||
if (name %in% names(app_state_options)) {
|
||||
return(app_state_options[[name]])
|
||||
} else {
|
||||
return(default)
|
||||
}
|
||||
@@ -199,11 +199,12 @@ shinyOptions <- function(...) {
|
||||
|
||||
# If not in a session, but we have a currently running app, modify options
|
||||
# at the app level.
|
||||
app_state <- getCurrentAppState()
|
||||
if (!is.null(app_state)) {
|
||||
if (isRunning()) {
|
||||
# Modify app-level options
|
||||
app_state$options <- dropNulls(mergeVectors(app_state$options, newOpts))
|
||||
return(invisible(app_state$options))
|
||||
setCurrentAppStateOptions(
|
||||
dropNulls(mergeVectors(getCurrentAppStateOptions(), newOpts))
|
||||
)
|
||||
return(invisible(getCurrentAppStateOptions()))
|
||||
}
|
||||
|
||||
# If no currently running app, modify global options and return them.
|
||||
@@ -218,9 +219,8 @@ shinyOptions <- function(...) {
|
||||
return(session$options)
|
||||
}
|
||||
|
||||
app_state <- getCurrentAppState()
|
||||
if (!is.null(app_state)) {
|
||||
return(app_state$options)
|
||||
if (isRunning()) {
|
||||
return(getCurrentAppStateOptions())
|
||||
}
|
||||
|
||||
return(.globals$options)
|
||||
|
||||
@@ -738,7 +738,7 @@ ShinySession <- R6Class(
|
||||
private$.outputOptions <- list()
|
||||
|
||||
# Copy app-level options
|
||||
self$options <- getCurrentAppState()$options
|
||||
self$options <- getCurrentAppStateOptions()
|
||||
|
||||
self$cache <- cachem::cache_mem(max_size = 200 * 1024^2)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/server.R
|
||||
% Please edit documentation in R/app-state.R
|
||||
\name{isRunning}
|
||||
\alias{isRunning}
|
||||
\title{Check whether a Shiny application is running}
|
||||
|
||||
Reference in New Issue
Block a user