1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/devmode.R
\name{devmode}
\alias{devmode}
\alias{in_devmode}
\alias{with_devmode}
\alias{devmode_inform}
\alias{register_devmode_option}
\alias{get_devmode_option}
\title{Shiny Developer Mode}
\usage{
devmode(
devmode = getOption("shiny.devmode", TRUE),
verbose = getOption("shiny.devmode.verbose", TRUE)
)
in_devmode()
with_devmode(devmode, code, verbose = getOption("shiny.devmode.verbose", TRUE))
devmode_inform(
message,
.frequency = "regularly",
.frequency_id = message,
.file = stderr(),
...
)
register_devmode_option(name, devmode_message = NULL, devmode_default = NULL)
get_devmode_option(
name,
default = NULL,
devmode_default = missing_arg(),
devmode_message = missing_arg()
)
}
\arguments{
\item{devmode}{Logical value which should be set to \code{TRUE} to enable Shiny
Developer Mode}
\item{verbose}{Logical value which should be set to \code{TRUE} display Shiny
Developer messages}
\item{code}{Code to execute with the temporary Dev Mode options set}
\item{message}{Developer Mode message to be sent to \code{\link[rlang:abort]{rlang::inform()}}}
\item{.frequency}{Frequency of the Developer Mode message used with
\code{\link[rlang:abort]{rlang::inform()}}. Defaults to once every 8 hours.}
\item{.frequency_id}{\code{\link[rlang:abort]{rlang::inform()}} message identifier. Defaults to
\code{message}.}
\item{.file}{Output connection for \code{\link[rlang:abort]{rlang::inform()}}. Defaults to \code{\link[=stderr]{stderr()}}}
\item{...}{Parameters passed to \code{\link[rlang:abort]{rlang::inform()}}}
\item{name}{Name of option to look for in \code{options()}}
\item{devmode_message}{Message to display once every 8 hours when utilizing
the \code{devmode_default} value. If \code{devmode_message} is missing, the
registered \code{devmode_message} value be used.}
\item{devmode_default}{Default value to return if \code{in_devmode()} returns
\code{TRUE} and the specified option is not set in \code{\link[=options]{options()}}. For
\code{get_devmode_option()}, if \code{devmode_default} is missing, the
registered \code{devmode_default} value will be used.}
\item{default}{Default value to return if \code{in_devmode()} returns
\code{TRUE} and the specified option is not set in \code{\link[=options]{options()}}.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Developer Mode enables a number of \code{\link[=options]{options()}} to make a developer's life
easier, like enabling non-minified JS and printing messages about
deprecated functions and options.
Shiny Developer Mode can be enabled by calling \code{devmode(TRUE)} and disabled
by calling \code{devmode(FALSE)}.
Please see the function descriptions for more details.
}
\section{Functions}{
\itemize{
\item \code{devmode()}: Function to set two options to enable/disable Shiny
Developer Mode and Developer messages
\item \code{in_devmode()}: Determines if Shiny is in Developer Mode. If the
\code{getOption("shiny.devmode")} is set to \code{TRUE} and not in testing inside
\code{testthat}, then Shiny Developer Mode is enabled.
\item \code{with_devmode()}: Temporarily set Shiny Developer Mode and Developer
message verbosity
\item \code{devmode_inform()}: If Shiny Developer Mode and verbosity are enabled,
displays a message once every 8 hrs (by default)
\item \code{register_devmode_option()}: Registers a Shiny Developer Mode option with an updated
value and Developer message. This registration method allows package
authors to write one message in a single location.
For example, the following Shiny Developer Mode options are registered:
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Reload the Shiny app when a sourced R file changes
register_devmode_option(
"shiny.autoreload",
"Turning on shiny autoreload. To disable, call `options(shiny.autoreload = FALSE)`",
devmode_default = TRUE
)
# Use the unminified Shiny JavaScript file, `shiny.js`
register_devmode_option(
"shiny.minified",
"Using full shiny javascript file. To use the minified version, call `options(shiny.minified = TRUE)`",
devmode_default = FALSE
)
# Display the full stack trace when errors occur during Shiny app execution
register_devmode_option(
"shiny.fullstacktrace",
"Turning on full stack trace. To disable, call `options(shiny.fullstacktrace = FALSE)`",
devmode_default = TRUE
)
}\if{html}{\out{</div>}}
Other known, non-Shiny Developer Mode options:
\itemize{
\item Sass:
}
\if{html}{\out{<div class="sourceCode r">}}\preformatted{# Display the full stack trace when errors occur during Shiny app execution
register_devmode_option(
"sass.cache",
"Turning off sass cache. To use default caching, call `options(sass.cache = TRUE)`",
devmode_default = FALSE
)
}\if{html}{\out{</div>}}
\item \code{get_devmode_option()}: Provides a consistent way to change the expected
\code{\link[=getOption]{getOption()}} behavior when Developer Mode is enabled. This method is very
similar to \code{\link[=getOption]{getOption()}} where the globally set option takes precedence.
See section "Avoiding direct dependency on shiny" for
\code{get_devmode_option()} implementation details.
\strong{Package developers:} Register your Dev Mode option using
\code{register_devmode_option()} to avoid supplying the same \code{devmode_default}
and \code{devmode_message} values throughout your package. (This requires a
\pkg{shiny} dependency.)
}}
\section{Avoiding direct dependency on shiny}{
The methods explained in this help file act independently from the rest of
Shiny but are included to provide blue prints for your own packages. If
your package already has (or is willing to take) a dependency on Shiny, we
recommend using the exported Shiny methods for consistent behavior. Note
that if you use exported Shiny methods, it will cause the Shiny package to
load. This may be undesirable if your code will be used in (for example) R
Markdown documents that do not have a Shiny runtime (\code{runtime: shiny}).
If your package can \strong{not} take a dependency on Shiny, we recommending
re-implementing these two functions:
\enumerate{
\item \code{in_devmode()}:
This function should return \code{TRUE} if \code{getOption("shiny.devmode")} is set.
In addition, we strongly recommend that it also checks to make sure
\code{testthat} is not testing.
\if{html}{\out{<div class="sourceCode r">}}\preformatted{in_devmode <- function() \{
isTRUE(getOption("shiny.devmode", FALSE)) &&
!identical(Sys.getenv("TESTTHAT"), "true")
\}
}\if{html}{\out{</div>}}
\item \code{get_devmode_option(name, default, devmode_default, devmode_message)}:
This function is similar to \code{getOption(name, default)}, but when the option
is not set, the default value changes depending on the Dev Mode.
\code{get_devmode_option()} should be implemented as follows:
\itemize{
\item If not in Dev Mode:
\itemize{
\item Return \code{getOption(name, default)}.
}
\item If in Dev Mode:
\itemize{
\item Get the global option \code{getOption(name)} value.
\item If the global option value is set:
\itemize{
\item Return the value.
}
\item If the global option value is not set:
\itemize{
\item Notify the developer that the Dev Mode default value will be used.
\item Return the Dev Mode default value.
}
}
}
When notifying the developer that the default value has changed, we strongly
recommend displaying a message (\code{devmode_message}) to \code{stderr()} once every 8
hours using \code{\link[rlang:abort]{rlang::inform()}}. This will keep the author up to date as to
which Dev Mode options are being altered. To allow developers a chance to
disable Dev Mode messages, the message should be skipped if
\code{getOption("shiny.devmode.verbose", TRUE)} is not \code{TRUE}.
\if{html}{\out{<div class="sourceCode r">}}\preformatted{get_devmode_option <- function(name, default = NULL, devmode_default, devmode_message) \{
if (!in_devmode()) \{
# Dev Mode disabled, act like `getOption()`
return(getOption(name, default = default))
\}
# Dev Mode enabled, update the default value for `getOption()`
getOption(name, default = \{
# Notify developer
if (
!missing(devmode_message) &&
!is.null(devmode_message) &&
getOption("shiny.devmode.verbose", TRUE)
) \{
rlang::inform(
message = devmode_message,
.frequency = "regularly",
.frequency_id = devmode_message,
.file = stderr()
)
\}
# Return Dev Mode default value `devmode_default`
devmode_default
\})
\}
}\if{html}{\out{</div>}}
}
The remaining functions in this file are used for author convenience and are
not recommended for all reimplementation situations.
}
\examples{
# Enable Shiny Developer mode
devmode()
in_devmode() # TRUE/FALSE?
# Execute code in a temporary shiny dev mode
with_devmode(TRUE, in_devmode()) # TRUE
# Ex: Within shiny, we register the option "shiny.minified"
# to default to `FALSE` when in Dev Mode
\dontrun{register_devmode_option(
"shiny.minified",
devmode_message = paste0(
"Using full shiny javascript file. ",
"To use the minified version, call `options(shiny.minified = TRUE)`"
),
devmode_default = FALSE
)}
# Used within `shiny::runApp(launch.browser)`
get_devmode_option("shiny.minified", TRUE) # TRUE if Dev mode is off
is_minified <- with_devmode(TRUE, {
get_devmode_option("shiny.minified", TRUE)
})
is_minified # FALSE
}
|