App displays images and works fine locally but not on a server

What is the output of ls -lah /srv/shiny-server?

I don't know. Which directory? I am still very unskilled here.

  total 8.0K
  drwxrwxrwx 2 root root 4.0K Feb  1 00:01 .
  drwxr-xr-x 3 root root 4.0K Jan 26 17:42 ..
  lrwxrwxrwx 1 root root   38 Jan 26 17:42 index.html -> /opt/shiny-server/samples/welcome.html
  lrwxrwxrwx 1 root root   37 Jan 26 17:42 sample-apps -> /opt/shiny-server/samples/sample-apps
  lrwxrwxrwx 1 root root   35 Feb  1 00:01 yurtzzle-website-shiny -> /home/ubuntu/yurtzzle-website-shiny

I think that directory shouldn't be owned by root. Usually it is owned by the user is deploying the app and that user is within a "shiny-apps" group along with the shiny user.

Also, I think you shouldn't use a symlink to your app it is better to do a copy of the folder or it will retain the same permissions as the origin folder.

It looked like the app was trying to render images. If those are stored in a directory that root can’t find because it’s in a path that it doesn’t have read permissions set correctly. The chmod 777 is explained in detail here .The only obvious reason it didn’t work in your install is that the app was directing user root to a file not under the directory that had access open to the world.

I also use an EC2 instance for developing and testing my apps, the shiny-server process is launched by root which is very common (although not the safest option) but the apps itself run as the shiny user (or whatever is configured in the run_as option). I have permissions set this way and apps can access any files inside www without any issues

ubuntu@ip-172-31-2-14:~$ ls -lah /srv/shiny-server/
total 56K
drwxrwxrwx 11 andres shiny-apps 4,0K ene 29 09:43 .
drwxr-xr-x  3 root   root       4,0K ene 26 13:01 ..
drwxrwxrwx  2 andres shiny-apps 4,0K ene 26 13:01 almacen
drwxrwxrwx  2 andres shiny-apps 4,0K ene 26 13:01 api_peru
drwxrwxrwx  3 andres shiny-apps 4,0K ene 26 13:01 bcp
drwxrwxrwx  8 andres shiny-apps 4,0K ene 29 10:03 .git
-rwxrwxrwx  1 andres shiny-apps  527 ene 26 13:01 .gitignore
-rwxrwxrwx  1 andres shiny-apps   14 ene 26 13:01 README.md
drwxr-xr-x  4 andres andres     4,0K ene 26 14:37 .Rproj.user
drwxrwxrwx  3 andres shiny-apps 4,0K ene 26 13:01 saldos
drwxrwxrwx  2 andres shiny-apps 4,0K ene 26 13:01 sensors
-rwxrwxrwx  1 andres shiny-apps  205 ene 29 09:43 shiny-server.Rproj
drwxrwxrwx  3 andres shiny-apps 4,0K ene 26 13:01 tienda
drwxrwxrwx  4 andres shiny-apps 4,0K ene 26 14:38 tpv

I want to emphasize, just because the shiny-server process is launched by root doesn't mean the app's are launched by root.

For example, here you can see the shiny-server process launched by root but the R process on which the app is running is launched by shiny

1 Like

Technocrat, that link for chmod 777 is broken.

Looks like I had a trailing space in the link https://www.linuxscrew.com/chmod-777

Oh man we're almost there. @lxy009, @andresrcs, @technocrat -- You guys are obviously pros. Permissions? Users? Paths? I had never considered these words before.

@andresrcs I copied the app into /srv/shiny-server and it almost worked. It rendered the top images, but not the central image. This central image(dressedYurt tmp.jpg' is written into the working directory, which is then displayed on the UI. It threw this error into the app logs:

    Listening on http://127.0.0.1:45525
    Warning in file(con, "wb") :
      cannot open file 'dressedYurt tmp.jpg': Permission denied
    Warning: Error in file: cannot open the connection
      117: file

There it is again. Permission denied. So I am surmising that when I copied the app into /srv/shiny-server, the permissions were inherited that allowed reading inside the directory but not writing?

I think that directory shouldn't be owned by root. Usually it is owned by the user is deploying the app and that user is within a "shiny-apps" group along with the shiny user.

So, how do I tell ubuntu that the entire 'yurtzzle-website-shiny' directory should be owned by the 'shiny' user? And how do I tell it that the 'shiny' user also has write access, to create the central image?

This is not mandatory nor the best practice security wise but it is a tested permissions config

sudo groupadd shiny-apps
sudo usermod -aG shiny-apps ubuntu
sudo usermod -aG shiny-apps shiny
cd /srv/shiny-server
sudo chown -R ubuntu:shiny-apps .
sudo chmod g+w .
sudo chmod g+s .
cd
# If the above doesn't work use this (not safe at all for a "production" setup).
sudo chmod 777 -R /srv/shiny-server

Do you mean the image file is created programmatically in execution time and it is stored in the app's root folder? if so, can you show the permissions for the app's folder?

ls -la /srv/shiny-server/yurtzzle-website-shiny

Speaking for myself. I'm not a pro, I'm just a data science DIYer who plays a lot with these things

I ended up using the chmod 777 last night...here's the permissions:

ubuntu@ip-172-31-22-111:~$ ls -la /srv/shiny-server/yurtzzle-website-shiny
total 360
drwxrwxrwx 4 ubuntu ubuntu   4096 Feb  2 01:33  .
drwxrwxrwx 3 root   root     4096 Feb  2 00:40  ..
drwxrwxr-x 8 ubuntu ubuntu   4096 Feb  2 00:40  .git
-rw-rw-r-- 1 ubuntu ubuntu   7172 Feb  2 00:40  app.R
-rw-rw-r-- 1 shiny  shiny  340170 Feb  2 16:09 'dressedYurt tmp.jpg'
drwxrwxr-x 8 ubuntu ubuntu   4096 Feb  2 00:40  www

And it works! Thank you guys so much for taking the time to help me. I really had no idea what issues were at play. I'm going to mark this as the solution, but please read the entire thread to get a feel for what the multiple solutions were.

1 Like

Have in mind that using 777 is not actually a solution but a walkaround or a convenience for testing. I really don't recommend this for deployment

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.