rstudio/shiny — pull request #75 by wch (2013-01-15 21:58:10+00:00)
Title: Add read-write wrapper class for Values

This is an first take for adding an object that provides reactive values, similar to `input`, except that you can both read and write to it.

Example tests:

```R
library(testthat)

# Create a values object
values <- reactiveValues()
values$a <- 3
# To access the value from the console, use isolate()
expect_equal(isolate(values$a), 3)
values$a <- 4
expect_equal(isolate(values$a), 4)

# Create with initialized values
values <- reactiveValues(a=1, b=2)
expect_equal(isolate(values$a), 1)
expect_equal(isolate(values$b), 2)

# Unnamed arguments, should throw error
expect_error(reactiveValues(1, b=2))

# If readonly, should throw error on assignment
values <- .createValues(Values$new(), readonly = TRUE)
expect_error(values$a <- 1)
```

Some comments and questions:

1. `reactiveValues()` is a user-friendly wrapper for `.createValues(Values$new())`.
1. `.createValuesReader()` is replaced with `.createValues()`. The `input` object is now created with `.createValues(shinyapp$session, readonly=TRUE)`
1. `.createValues` could use a better name. Maybe `createReactiveValues`?
1. Adding double-square-bracket indexing would be useful so that people can use strings to access the variables, e.g. `x <- "a"; values[[x]]`.
1. The `reactiveValue()` function `ReactiveValue` class shouldn't be necessary anymore. Porting over the existing tests should be simple.

Also, I'm thinking the `ShinyServer(input, output)` function should _not_ take `values` as another argument, for the following reasons: if `values` is created _outside_ of that function and then passed in, it might be confusing to R programmers that `values` is pass-by-reference (right?) -- and if were pass-by-value, that would be confusing in other ways. But there may be something I'm missing about how that would work.