In a module, it gives an error when I try to assign to session variable.
Error in $<-.session_proxy
(*tmp*
, parent, value = "someDataToBeUsedWithinThisSession") :
Attempted to assign value on session proxy.
Also session variable does not contain anything from the server function, no user data, nothing. Apparently the session variable inside a module is a "session proxy" variable scoped to that module and not connected to the session variable in the server function. However, if this local session variable has no data and cannot be written to, what is the purpose of it?
moduleServer(id, function(input, output, session) {
session$data <- "someDataToBeUsedWithinThisSession"
....
})
1 Like
shinySessions are R6 Objects; they include a lot of functionality and they contain data, but they arent intended for Shiny 'user-developers' to directly manipulate. They should be considered as infrastructure that make R shiny work.
The source code and documentation is here :
Session object — session
1 Like
Did you mean to use session$userData
instead? That is an empty slot that you can write data to per the docs nirgraham's already linked to. The reason session$data
doesn't work is that the top level of R6 objects are locked.
1 Like
Thank you both for your responses and useful information you provided. Unfortunately, it seems that we are talking about different session objects. The session object in the server function has the userData and other properties, but the session object within a shiny module doesn't seem to have anything. It has only two properties, "parent" and "overrides", both of which are null. And it itself is of type "session_proxy", not "ShinySession" like the session variable in the top-level server function. I couldn't find much information about how to use this using Copilot/Google.
session variable in module:
The parent is the apps session. The source code isnopen so you can investigate shiny/R/modules.R at 13ca8dfc572198db2e8fd168a5da6656096aa6df · rstudio/shiny · GitHub
But what is motivating your interest ? Are you unable to implement your desired module without directly manipulating session?
1 Like
Oh, I thought it would be good to pass data from the parent apps session to the modules; that's one less parameter I need to pass into the module. Thanks for the hint! although I didn't really understand the source code, but I realized that by doing session$userData$xyz in the module, I can get the session$userData$xyz from the apps session.
Its great you have satisfied yourself you have a solution, but are you confident you arent overlooking traditinak ways of putting data into a module by passing reactives, using the module call syntax ?