Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny list2env

Tags:

r

shiny

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 ?

like image 488
Sri Avatar asked Jun 04 '15 21:06

Sri


1 Answers

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.)

like image 91
MrFlick Avatar answered Oct 12 '22 00:10

MrFlick