When declaring a variable from an observeEvent function of the server using <<-
it is declared as a global variable and becomes available to all users of the app. How should one declare a variable from an observeEvent that would be accessible to other observeEvent functions, but not to other users of the app?
Using the following code, when I open two sessions of the app (with Shiny Server) the generated value is shared across both sessions.
library(shiny)
ui <- fluidPage(
actionButton("btn1", "generate a value"),
actionButton("btn2", "show a value")
)
server <- function(input, output, session) {
observeEvent(input$btn1, myvalue <<- runif(n=1) )
observeEvent(input$btn2, showModal(modalDialog(myvalue)))
}
shinyApp(ui, server)