Passing environment variables to shiny app

21 views
Skip to first unread message

henryk....@gmail.com

unread,
Sep 22, 2016, 3:27:43 AM9/22/16
to Shiny - Web Framework for R
Hi All

I've read that passing environment variables is currently not supported (https://groups.google.com/forum/#!topic/shiny-discuss/nNs0kztwdWo).

Since it is a reasonable (and e.g. in cloud setups common) way to pass configuration to an app I propose that shiny-server passes through all environment variables starting with "SHINY_", e.g. SHINY_MYENVVAR.

This can be easily implemented by the patch below:
----

diff --git a/lib/worker/app-worker.js b/lib/worker/app-worker.js

index 9f558fa..dfc7325 100644

--- a/lib/worker/app-worker.js

+++ b/lib/worker/app-worker.js

@@ -309,14 +309,22 @@ var AppWorker = function(appSpec, endpoint, logStream, workerId, home) {

       );

     })

     .then(function() {

+      var env =  map.compact(

+          _.extend(

+             _.omit(process.env,

+               function(v,k){ return k.substr(0,6)!=='SHINY_'; }

+             ),

+             {

+             'HOME' : home,

+             'LANG' : process.env['LANG'],

+             'PATH' : process.env['PATH']

+             }

+          )

+      );

       self.$proc = child_process.spawn(executable, args, {

         stdio: ['pipe', 'pipe', logStream],

         cwd: appSpec.appDir,

-        env: map.compact({

-          'HOME' : home,

-          'LANG' : process.env['LANG'],

-          'PATH' : process.env['PATH']

-        }),

+        env: env,

         detached: true  // So that we can send SIGINT not just to su but to the

                         // R process that it spawns as well

       });

----

What do you think?

Best,
Henryk
Reply all
Reply to author
Forward
0 new messages