Couple questions in here that I'll give my thoughts on.
Is
reactiveValuesfunction completely useless?
- No.
inputsandclientDataarea actuallyreactiveValuesobjects. They are helpful when sets (with possibly unknown names) of reactive information is necessary. - Of the objects that I create, they are 95%
reactiveobjects.
Can all reactivity needs for assigning values in a shiny app be satistfied using
reactive()andeventReactive()?
- No. That being said, a lot of user input handling will only be using
reactive()andeventReactive(). - Example: Let's say you want to make a "deduplication" reactive. "It should react to an expression, but it should not update the value unless it's a new value." This would require a reactive expression, an observer, and a reactiveVal.
dedupe <- function(expr) {
r <- reactive(expr)
deduped <- reactiveVal(NULL)
observe({
deduped(r())
})
return(deduped)
}
Is
reactiveValues()bad code smell?
- No. I think of
reactiveValues()as a reactivelist(), rather than a reactive object. Since it is a list, there are a few extra methods that work with areactiveValues()list object. Example:var <- reactiveValues(); r <- reactive()names(var): If this was done with areactive, it'd have to be:names(r()), assumingrproduces a list object.as.list(var): will produce a list object with all key value pairs.
tldr;
- Use reactiveValues if you'd like a
reactive()list. - 95% of my code is
reactive()orobserveEvent() - Use
observe()only if side effects are necessary.