Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thisisnic/shiny_reference_semantics_example
Example code to show how reactiveValues use reference semantics
https://github.com/thisisnic/shiny_reference_semantics_example
Last synced: 1 day ago
JSON representation
Example code to show how reactiveValues use reference semantics
- Host: GitHub
- URL: https://github.com/thisisnic/shiny_reference_semantics_example
- Owner: thisisnic
- Created: 2018-10-18T09:53:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-18T10:33:42.000Z (over 6 years ago)
- Last Synced: 2024-12-03T18:52:09.078Z (about 2 months ago)
- Language: R
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Shiny `reactiveValues` Reference Semantics
In Shiny, `reactiveValues()` can be used to create a list-like
reactive object. However, this object has special properties.Normally in R, scoping rules mean that when you pass an object into a function
as a parameter, __copy-on-modify__ semantics are used. In other words, a copy of
that object is passed into the function, and so this copy is the one which the
function can alter, and the original object is not modified.However, in the case of objects created using `reactiveValues()`, this is not
the case. Objects created using `reactiveValues()` are R6 objects, and these kinds of objects use
__reference semantics__. This means that when we pass them into a function as a parameter,
it is a reference to the original object that is is passed in, and so modifications made within the scope of the function are reflected outside of the function as well as within it.The app in this repo shows a brief example of this.
See the reactiveValues section [in this blog post by yindeng for more information](https://shinydata.wordpress.com/2015/02/02/a-few-things-i-learned-about-shiny-and-reactive-programming/).