Using R's system() command with shiny-server on Linux

1,942 views
Skip to first unread message

Blake Arensdorf

unread,
Nov 25, 2013, 2:48:01 PM11/25/13
to shiny-...@googlegroups.com

Hi,

I'd like my shiny app to kick off a certain system command every time a users accesses it, so I'm trying it out with basic commands to see if it would work. Currently, running the following from R itself completes with the expected result:

system("echo myPassword | sudo -S mkdir ~/testdir")

However, when I put that same command into server.r, nothing happens. I've tried doing the same with other commands and it seems like shiny just skips over the command entirely.

How can I get this to work? 

Thanks.

Stéphane Laurent

unread,
Nov 25, 2013, 3:49:27 PM11/25/13
to shiny-...@googlegroups.com
I'm not sure that "~/"  works on the server.

Blake Arensdorf

unread,
Nov 25, 2013, 3:51:54 PM11/25/13
to shiny-...@googlegroups.com
I actually didn't use "~/", I just didn't want to type my actual directory structure in here. I tried to create it in "/var/...", so that shouldn't be the issue.

Blake Arensdorf

unread,
Nov 25, 2013, 3:57:05 PM11/25/13
to shiny-...@googlegroups.com
I've also found that it doesn't have anything to do with whether I'm piping it my sudo password or not either - I've tried doing it on a command that doesn't require sudo and it still doesn't do anything. There must be something going on where shiny-server won't run system commands?

Stéphane Laurent

unread,
Nov 25, 2013, 3:59:45 PM11/25/13
to shiny-...@googlegroups.com
No, `system()` works inside shiny server. For example my app here runs a system command:  http://glimmer.rstudio.com/stla/ImageMagickCompression_single/ 
I don't knwo what your command is supposed to do.

Blake Arensdorf

unread,
Nov 25, 2013, 4:02:42 PM11/25/13
to shiny-...@googlegroups.com
Right now I can't even get "sudo mkdir /var/(path here)" to run. When I open up R in linux and run the command from the R command line, it works. It creates the directory in the expected location. Then I go to delete the directory and put that line inside my shinyServer function and nothing happens. (I've also tried piping my sudo password as I mentioned above). 

Blake Arensdorf

unread,
Nov 25, 2013, 4:07:09 PM11/25/13
to shiny-...@googlegroups.com
I'm thinking it might have to do with permissions on my server. It's possible that using R to run the command is allowed but that I don't have permissions to do the same from shiny-server. Unless anyone has other ideas, I'll look into that.

Stéphane Laurent

unread,
Nov 25, 2013, 4:50:16 PM11/25/13
to shiny-...@googlegroups.com
Where do you run the Shiny app ? Of course you need writing permissions to create a directory.

Blake Arensdorf

unread,
Nov 25, 2013, 4:55:24 PM11/25/13
to shiny-...@googlegroups.com
Right. Again, The command works when I run it from R.

Stéphane Laurent

unread,
Nov 25, 2013, 5:52:43 PM11/25/13
to shiny-...@googlegroups.com
Thsi is not what I meant. The Shiny app, you run it locally on your computer, or on a server ? 

Blake Arensdorf

unread,
Nov 25, 2013, 6:20:52 PM11/25/13
to shiny-...@googlegroups.com
I just found out that it's a permissions deal (on the server) and has nothing to do with shiny. Thanks for your help!

Joe Cheng

unread,
Nov 26, 2013, 12:20:09 PM11/26/13
to Blake Arensdorf, shiny-...@googlegroups.com
Keep in mind that by default shiny-server runs applications as the "shiny" user, who should be a low-privileged user. If sudo worked for that user without a password... *shudder*. Any security vulnerability in your app or in the Shiny stack would mean an attacker could totally own your machine!

If you must have some kind of high-privilege-requiring task kicked off by actions by users of Shiny apps, then try to have the Shiny app just add tasks to a queue of some kind, and have a higher-privileged process running and waiting for items to arrive in that queue. You could use something like rzmq, or even just put files in a directory that the shiny user has write access.


On Mon, Nov 25, 2013 at 3:20 PM, Blake Arensdorf <blake.a...@gmail.com> wrote:
I just found out that it's a permissions deal (on the server) and has nothing to do with shiny. Thanks for your help!

--
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.

Reply all
Reply to author
Forward
0 new messages