Shiny Server global variables

3,010 views
Skip to first unread message

Brian Bolt

unread,
Apr 19, 2013, 2:04:16 PM4/19/13
to shiny-...@googlegroups.com
Hi,
What is the best way to manage global variables across all apps.  Is there a "global.R" that can be evaluated on shiny-server startup?

Thanks,
Brian

Winston Chang

unread,
Apr 19, 2013, 2:24:26 PM4/19/13
to shiny-...@googlegroups.com
If you're asking how to share data across different client sessions with the same app, you should define them outside of the shinyServer() call. See here for more information:

If you're asking how to share variables across different Shiny apps, there's really no way to do that. You would have to write data to a file from one app and read it in from another.

-Winston



--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brian Bolt

unread,
Apr 19, 2013, 3:27:56 PM4/19/13
to shiny-...@googlegroups.com
Thanks. My goal is to have a global "config" data frame that is accessible to all of the apps on startup.

Alex Flyax

unread,
Aug 18, 2015, 11:24:56 PM8/18/15
to Shiny - Web Framework for R
Hi,

I need to to upload a file in memory which should be accessible to both the server.R and ui.R at the same time. If I only load in in server.R, ui.R doesn’t see it. When I run an instance locally, I just run a file called global.R which uploads the file into memory. Is there a way to do that when running Shiny Server (Pro)? I want all user to have access to this file, but the file itself won’t be changed.

Thanks,
Alex

Joe Cheng

unread,
Aug 19, 2015, 11:56:39 AM8/19/15
to Alex Flyax, Shiny - Web Framework for R
If you put a global.R file in your app directory, it will automatically be invoked when the app starts up--no need to source it yourself. Any variables defined there will be available in both ui and server.
--
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.

Michael Frank

unread,
Oct 11, 2015, 6:32:10 AM10/11/15
to Shiny - Web Framework for R
Hi,

I am running across the same problem right now. I have build a view apps for a client. This apps need to access the same data. I would like to do that with global reactive variables. That works fine inside every app itself. But across apps a change of the global variable is ignored. I assume that this has to do with the different R sessions used by the shiny server pro for different apps. Any ideas here without using a reactiveFileReader to make changes public?

Best,
Michael

Joe Cheng

unread,
Oct 11, 2015, 9:57:20 AM10/11/15
to Michael Frank, Shiny - Web Framework for R
Is there a reason not to use a reactiveFileReader? That's probably the easiest way, and if you want the values to be persistent, the only way.
--
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.

Michael Frank

unread,
Oct 11, 2015, 11:23:47 AM10/11/15
to Shiny - Web Framework for R, dr.micha...@googlemail.com
The reason not using reactiveFileReader is the amount of data and the rate it changes.
But it seems I have to live with that.

Thanks for the quick answer!!

Joe Cheng

unread,
Oct 11, 2015, 11:45:38 AM10/11/15
to Michael Frank, Shiny - Web Framework for R
It would be conceivable to use another interprocess communication mechanism, like shared memory. But I don't know of any such mechanism today. Also, if you have writes happening simultaneously, you need to worry about two processes interleaving their writes which would end up causing the file to be corrupted. You can deal with this I believe, by not writing directly to the file, but by writing to a temp file in the same directory, then deleting the file and renaming the temp file to the permanent file name.

Sijie Chen

unread,
Oct 17, 2015, 2:50:01 AM10/17/15
to Shiny - Web Framework for R
Why not trying using a file or database to share information between different R applications? It may not be a efficient method, but easy.
Reply all
Reply to author
Forward
0 new messages