What is happening is that the data is being loaded into the environment of the function which then disappears when the function returns. So you either have to return the values you want from RData in a list, or in an environment as shown below:
> x = 1:10 # create some data > y = 2 > z = 3 > save.image('test.RData') # save workspace in a file > rm(list = ls()) # clear workarea > f.loadData <- function() # read in the RData file + { + myData = new.env() # create environment for the data + load('test.RData', envir = myData) + myData # return the data + } > > # just call the function > f.loadData() <environment: 0x0000000015840578> > ls() # data not there [1] "f.loadData" > some <- f.loadData() # load and save return value > ls() # now 'some' is there [1] "f.loadData" "some" > some$x # access some value [1] 1 2 3 4 5 6 7 8 9 10 > On Sat, Aug 10, 2013 at 5:27 AM, ivan <i.pet...@gmail.com> wrote: > Dear R Community > > I am trying to do the following. I have two .Rdata objects, e.g. res1.Rdata > and res2.Rdata. I want to achieve that the user can select the object of > interest within shinyapp. > > I.e. in ui.R I have: > > radioButtons("object", "Object", > list("res1" = 1, > "res2" = 2 > )), > > In server.R I have: > > objectofinterest <- reactive({ > as.numeric(input$object) > }) > .GlobalEnv <- reactive({ > load.data(objectofinterest()) > }) > > where > > load.data=function(x){ > if (x==1){ > load('../shinyapp/res1.Rdata', envir=.GlobalEnv) > } > if (x==2){ > load('../shinyapp/res2.Rdata', envir=.GlobalEnv) > } > } > > using load.data in R directly works perfectly. But when I start shinyapp, > it seems that shinyapp cannot get the objects. What am I doing wrong? > > Thank you!! > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.