How to force reload after changes in global.r

2,346 views
Skip to first unread message

Dieter Menne

unread,
Mar 14, 2013, 8:11:00 AM3/14/13
to shiny-...@googlegroups.com
When I make changes in global.R, I have to restart shiny to make it effective. This is easy with the local shiny app, but with a server, it is messy, requiring an open ssh session.

Is there an easy way to force reload of global.r? Or did I miss something very obvious?

Dieter

Dieter Menne

unread,
Mar 14, 2013, 8:26:25 AM3/14/13
to shiny-...@googlegroups.com

Answering my own question:

Joe Cheng wrote in another thread:

"The Shiny app should automatically exit 5 seconds after the last browser leaves it. Unfortunately there is not a way to force it to restart right now, although we hope to add that functionality soon."

Fair enough. I am just surprised that the server note the browser leaving.

Thomas Johnson

unread,
Mar 6, 2018, 7:38:01 PM3/6/18
to Shiny - Web Framework for R
They must have added a feature for this at some stage.

Putting a file called restart.txt (or updating its time stamp) will cause a refresh of global.R http://docs.rstudio.com/shiny-server/#restarting-an-application

David Hindley

unread,
Oct 9, 2020, 6:55:19 AM10/9/20
to Shiny - Web Framework for R
Was any feature added to shiny for this?  If not, how do you execute the linux "touch restart.txt" command effectively within a shiny app to force reload - is it best via a user-activated action button perhaps?  Is session$reload() a solution - in which case how should that be used within a shiny app?

My need for this feature stems from the situation where I update a CSV file on the server (which is loaded in global.R), and want to force a reload of it when a new shiny server session is launched - at present, it just retains the old CSV file when a new user session is launched (where an existing session was previously loaded and is still open with the old CSV file).

Many thanks.

David.

Joe Cheng

unread,
Oct 9, 2020, 3:03:38 PM10/9/20
to David Hindley, Shiny - Web Framework for R
You could use reactiveFileReader to have all sessions instantly react when the csv file changes. See the "cross-session reactive file reader" example here: https://shiny.rstudio.com/reference/shiny/latest/reactiveFileReader.html

If you ONLY want the csv file changes to be detected for new sessions, you could do the same thing, but wrap each read of the reactiveFileReader in isolate() (perhaps write a function for this), e.g.:

fileData <- local({
  rfr <- reactiveFileReader(1000, NULL, 'data.csv', read.csv)
  function() { isolate(rfr()) }
})

Then in your reactive expressions and outputs, call `fileData()`. (This construction with using local() is a little weird, but the nice thing about it is it makes the rfr object "private", assuming that's desirable in your case.)

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/f64709d9-c81b-43ca-93e3-a4f49839404bn%40googlegroups.com.

David Hindley

unread,
Oct 10, 2020, 5:58:05 AM10/10/20
to Joe Cheng, Shiny - Web Framework for R
Joe

Excellent.  Many thanks.  I will try one of those suggestions.

David.
Reply all
Reply to author
Forward
0 new messages