Global.R

37 views
Skip to first unread message

Aaron Clark

unread,
Aug 23, 2016, 3:04:38 PM8/23/16
to Shiny - Web Framework for R
In my shiny app, data is updated daily, and so are some global variables my app needs to function correctly. Therefore, every time the underlying data updates I overwrite a file called "stage_data.Rdata" that contains the workspace needed by both my ui.R and server.R programs.

Here is the contents of global.R:

# clear workspace and load in new workspace just in case its changed
rm(list=ls())
load("stage_data.Rdata")


The problem: if global.R is not changed and re-saved, shiny server doesn't seem to re-run global.R and thus, my statement: load(stage_data.Rdata) doesn't run either. As a result, I'm working with old workspace variables until I intervene. Specifically, I open global.R and make some small change (like adding a space or #) and re-saving the program. If I restart shiny server, that also works. How can I make shiny server read global.R every session without my intervention?


Sigbert Klinke

unread,
Aug 24, 2016, 4:26:33 AM8/24/16
to Shiny - Web Framework for R
Hi,

why do not integrate the data loading in observe or reactive context? Each context is run once when the session is started, e.g. like

  if (is.null(input$someinput)) { # first run
    rm
(list=ls()) # maybe it would be wiser to delete only the necessary objects
    load
("stage_data.Rdata")  
 
}

Best Sigbert
Reply all
Reply to author
Forward
0 new messages