| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/reactives.R |
| 3 |
\name{freezeReactiveVal} |
| 4 |
\alias{freezeReactiveVal} |
| 5 |
\alias{freezeReactiveValue} |
| 6 |
\title{Freeze a reactive value} |
| 7 |
\usage{ |
| 8 |
freezeReactiveVal(x) |
| 9 |
|
| 10 |
freezeReactiveValue(x, name) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{x}{For \code{freezeReactiveValue}, a \code{\link[=reactiveValues]{reactiveValues()}} |
| 14 |
object (like \code{input}); for \code{freezeReactiveVal}, a |
| 15 |
\code{\link[=reactiveVal]{reactiveVal()}} object.} |
| 16 |
|
| 17 |
\item{name}{The name of a value in the \code{\link[=reactiveValues]{reactiveValues()}} object.} |
| 18 |
} |
| 19 |
\description{ |
| 20 |
These functions freeze a \code{\link[=reactiveVal]{reactiveVal()}}, or an element of a |
| 21 |
\code{\link[=reactiveValues]{reactiveValues()}}. If the value is accessed while frozen, a |
| 22 |
"silent" exception is raised and the operation is stopped. This is the same |
| 23 |
thing that happens if \code{req(FALSE)} is called. The value is thawed |
| 24 |
(un-frozen; accessing it will no longer raise an exception) when the current |
| 25 |
reactive domain is flushed. In a Shiny application, this occurs after all of |
| 26 |
the observers are executed. \strong{NOTE:} We are considering deprecating |
| 27 |
\code{freezeReactiveVal}, and \code{freezeReactiveValue} except when \code{x} is \code{input}. |
| 28 |
If this affects your app, please let us know by leaving a comment on |
| 29 |
\href{https://github.com/rstudio/shiny/issues/3063}{this GitHub issue}. |
| 30 |
} |
| 31 |
\examples{ |
| 32 |
## Only run this examples in interactive R sessions |
| 33 |
if (interactive()) { |
| 34 |
|
| 35 |
ui <- fluidPage( |
| 36 |
selectInput("data", "Data Set", c("mtcars", "pressure")), |
| 37 |
checkboxGroupInput("cols", "Columns (select 2)", character(0)), |
| 38 |
plotOutput("plot") |
| 39 |
) |
| 40 |
|
| 41 |
server <- function(input, output, session) { |
| 42 |
observe({ |
| 43 |
data <- get(input$data) |
| 44 |
# Sets a flag on input$cols to essentially do req(FALSE) if input$cols |
| 45 |
# is accessed. Without this, an error will momentarily show whenever a |
| 46 |
# new data set is selected. |
| 47 |
freezeReactiveValue(input, "cols") |
| 48 |
updateCheckboxGroupInput(session, "cols", choices = names(data)) |
| 49 |
}) |
| 50 |
|
| 51 |
output$plot <- renderPlot({ |
| 52 |
# When a new data set is selected, input$cols will have been invalidated |
| 53 |
# above, and this will essentially do the same as req(FALSE), causing |
| 54 |
# this observer to stop and raise a silent exception. |
| 55 |
cols <- input$cols |
| 56 |
data <- get(input$data) |
| 57 |
|
| 58 |
if (length(cols) == 2) { |
| 59 |
plot(data[[ cols[1] ]], data[[ cols[2] ]]) |
| 60 |
} |
| 61 |
}) |
| 62 |
} |
| 63 |
|
| 64 |
shinyApp(ui, server) |
| 65 |
} |
| 66 |
} |
| 67 |
\seealso{ |
| 68 |
\code{\link[=req]{req()}} |
| 69 |
} |