I have a shiny application in which the server.R looks like below :
shinyServer(function(input, output,session) {
temp<-reactive({
obj1<-read.csv(.....)
v1<-c("obj2")
lst<-lapply(v1,read.csv(....)
list2env(lst)
...
})
I'm creating an object directly in the reactive function called obj1
and also creating obj2
using list2env. Both obj1
and obj2
are not in the same environment. What is the environment I'm in when I'm inside a reactive function?
Also, I don't want to use .GlobalEnv
in list2env
as it would make this object available across all user sessions. How do I make list2env
create obj2
in the same environment as obj1
?
The environment()
function will return the current environment. Thus if you use it inside a function, it will return the function's environment. You can then use that with
list2env(lst, envir=environment())
(Although personally I almost always find it easier to keep data in a list rather than create a bunch of separate variables in the environment.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With