Inside a Shiny server function, you can create a variable, say
S, that is specific to that session. However, to store things in
S from inside a function like
render..., observe..., reactive... etc, you have to use
<<- rather than
=. When you forget that detail you have a bug that is really hard to find.
On the other hand, you can use
session$userData instead of
S. You can store things in
session$userData from inside a function using either
=. The disadvantage is just that it’s a lot of characters to put in front of every variable.
The third option is to use a reactiveValue, say
RV = reactiveValues(). The name is short and you can store things in it from inside functions with
=. However, if the items you’re storing are just global variables and don’t need to be reactive, there is probably some kind of performance hit to using this method.
Does anyone know how bad the performance hit is or have any other suggestions for the best way to store session-specific data?