简体   繁体   中英

loading a .RData file into session but no object loaded in Shiny

I got my analysis results in R (an object called obj ) and save it as an .RData file obj-result.RData . Now in Shiny, at the beginning of the ui.R file, I put load("obj-results.RData") so that each time Shiny is run, this object can be loaded into R session, ie I expect that the obj object would be available to use in subsequent steps, such as obj@data , obj@sample , etc.

However, I find that load won't make the obj object available in current R session, so that Shiny could not find the quantities required. Is there anything I missed in loading the .RData object? Thank you so much!

The answer is that, whenever an object is used in the ui.R and/or server.R , the relevant objects must be loaded in the same file. Otherwise, shiny won't know where to find the object from other files (even they're in the same directory and loaded).

I also load a .RData file in my deployed ShinyApp ; my app works from this file. I also had difficulties to understand how the loading worked. In this example here the statement load(...) is located in the server.R . This manner to proceed didn't work in my ShinyApp (the app was displayed but became immediately gray) - I don't know why. The solution was only to put the load(...) statement in a global.R file : load("./data/obj-result.RData", envir=.GlobalEnv) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM