Closed happyshows closed 9 years ago
Could you supply a full reproducible example?
@wch I tried to isolate the problem and it seems that in 0.11.1, I can modify session object within function(session,input,output) but with 0.11.1.9, system will throw error : Unhandled error in observer: cannot add bindings to a locked environment
library(shiny)
svr <- reactiveValues(conCount = 0)
server <- function(session,input, output) { session$lockDisabled <- NULL }
ui <- fluidPage( h6('') )
shinyApp(ui = ui, server = server)
Oh, I see what you're doing. That's the expected behavior - you aren't allowed to add new fields to the session
object.
Why are you trying to do that? There is likely another solution for what you're trying to do.
If you want a session-scoped variable, just declare it as a normal variable inside of the Shiny server function. See this article: http://shiny.rstudio.com/articles/scoping.html
To assign to such variables from inside of observers and whatnot, use <<- for assignment instead of <-. (These are just normal R lexical scoping https://www.stat.auckland.ac.nz/~ihaka/downloads/lexical.pdf semantics, nothing particular to Shiny.)
On Wed, May 6, 2015 at 9:38 AM, Winston Chang notifications@github.com wrote:
Oh, I see what you're doing. That's the expected behavior - you aren't allowed to add new fields to the session object.
Why are you trying to do that? There is likely another solution for what you're trying to do.
— Reply to this email directly or view it on GitHub https://github.com/rstudio/shiny/issues/822#issuecomment-99531945.
thanks, I think I understand the root cause but was a bit surprised that it didn't throw any error before.
To anyone curious, the same error is thrown if you're building a custom R object and try to assign a value to a variable you didn't initialize.
Thanks for that info @SJCaldwell
Hi,
I have observe the following error with the 0.11.1.9xxx. The error went away as I switched back to the stable version on CRAN. This error will pop up to basically any attempt to create a reactivevalueslist. No matter outside or inside the function(input, output, session)
Warning in run(timeoutMs) : Unhandled error in observer: cannot add bindings to a locked environment
my code in server.R svr <- reactiveValues(conCount = 0) function(input, output, session) { ... }