Load variables from shiny app to RGlobalEnv

Is it possible get a value from the shiny app and the load in the Global Environment in running time?

I have a shiny app and for now, I can load a variable from the shiny app in the global environment but this only works when I close my shiny session.

You can run the example


ui <- fluidPage(
  headerPanel("Example reactiveValues"),
  
  mainPanel(
    
    # input field
    textInput("user_text", label = "Enter some text:", placeholder = "Please enter some text."),
    actionButton("submit", label = "Submit"),
    
    # display text output
    textOutput("text"))
)

server <- function(input, output) {
  # observe event for updating the reactiveValues
  observeEvent(input$submit,
               {
                 text_reactive$text <- input$user_text
                 #assign("data", text_reactive$text,envir=.GlobalEnv)
                 
               })
  
  eventReactive(input$submit,{
    assign("data", text_reactive$text,envir=.GlobalEnv)
    
  })
  
  # reactiveValues
  text_reactive <- reactiveValues(
    text = "No text has been submitted yet."
  )
  
  # text output
  output$text <- renderText({

    
  })
}

shinyApp(ui = ui, server = server)

But How can I load the variable load in the Global Env but without closing my shiny app?

you should think very hard about if using global env variables is wise, there are probably some good use cases but they would be rare I think, best avoided where possible.
That said, it's incorrect to use eventReactive when you are not making a reactive value but doing an observe type action so replace the eventReactive with

  observeEvent(input$submit,{
    cat("submitted\n")
    assign("data", text_reactive$text,envir=.GlobalEnv)
    datafromglob <- get("data",envir = .GlobalEnv)
   cat("data from glob is \n",datafromglob,"\n")                 
  })