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

Hello. I have tried almost everything to fix this, and have spent a couple weeks writing this (I hadn't written a shiny app in 9 years--happy to see all the advancements!), and days looking for a solution. I developed a shiny app that uses the magick package to produce user generated images. It works exactly as intended locally. You can run it from your console (I think--I can anyway) with the runGitHub function:

        runGitHub('yurtzzle-website-shiny','pcmckann')

I believe that you can see the public code on github, if not, I can amend this post with the code. It doesn't display in the RStudio pop-up (another clue?), but does display when you click the 'Open in Web Browser' button.

I then made an EC2 instance on AWS and deployed the app to the server (also brand new to me). The app partially displays on the server but will not display any of the images.

Here is the error as seen in the log files on the server:

        Listening on http://127.0.0.1:41249
        Warning: Error in if: argument is of length zero
          99: session$fileUrl
          98: transform
          97: func
          95: f
          94: Reduce
          85: do
          84: hybrid_chain
          83: renderFunc
          82: output$roof
           1: runApp

I will have hundreds of images in the final version of this, so I put them into subfolders in the www folder. I am guessing that if I dump all of them into the www folder, eliminating the subfolders in www, that this will fix it. But I really don't know if that's the problem, and if I can avoid that re-write, I will. I've just reached that certain point where I would love another pair of eyes on this.

If you see an easier fix, please let me know. Thanks for your help.

From a terminal session

shiny::runGitHub('yurtzzle-website-shiny','pcmckann')

opens a browser window with the cute outbuilding. And it works from the console in the RStudio IDE, either directly or by running a source pane.

The following (re subdirectories) also works there

shiny::runGitHub("shiny_example", "rstudio", subdir = "inst/shinyapp/")

Any chance that you are running the current Elspeth Geranium on Ventura?

Hi technocrat. Thanks for the reply. No, I am using Windows 10 on my home machine. The server is running ubuntu 22.04. I do not have RStudio installed on the server, just base R with associated packages installed. The shiny example app does display and work on the server.

In case you reply again soon, or anyone else does, I am leaving town with no internet access today. I won't be able to respond for a few days.

shiny spawns its own server. Might the user it runs under lack permissions?

I don't think that's the problem. I say that because a webpage is produced by the server, it just won't display the images (the log provided above shows the error message it throws). But I will look into it. What do you mean that "shiny spawns its own server?"

The website it produces: http://54.186.224.118:3838/yurtzzle-website-shiny/

I checked the R package library of the user 'shiny' on the EC2 instance, and there is indeed the magick package installed for the user named 'shiny'. As far as permissions, I don't know how to check on those yet.

You might want to try using shinyapps first on the free tier and see if it works there. If it works there, then it's probably a server setup issue with EC2. Or maybe that's a good enough solution for your needs.

Also, on the EC2, I'm assuming you are running the open source version of Shiny Server. Was there any issue installing that? It can take some time to figure out the configuration correctly.

You may want to search AMIs that have shiny server already set up.

Thanks for those comments. I will definitely explore your suggestions.

I installed the shiny server from Shiny Server - Posit, using these commands:

  sudo apt-get install gdebi-core
  
  wget https://download3.rstudio.org/ubuntu-18.04/x86_64/shiny-server-1.5.20.1002-amd64.deb
  
  sudo gdebi shiny-server-1.5.20.1002-amd64.deb

It didn't seem to have an issue installing. The sample app seems to work. I did have an issue where I had to install libcurl separately...but it's honestly kind of fuzzy now.

have you checked the shiny-server logs on the server?
There should be one for the server itself.
For the errors related to the specific app, you may want to get onto the app first to start a session and then checkout the process/session log.

another thing to think about, albeit it will cost more, is to run the EC2 with a windows server. It won't pinpoint the problem, but it might get you up and running for now.

Also a thing to consider in general is when you're developing on different environments e.g, windows local and linux in production. You may consider to Docker-ize things so you can test it locally but mimicking the end environment more closely.

I posted the log from the server in the original post that shows the error thrown by the application.

It makes no sense to me, but I was hoping it did for someone else. OK. I will look up Docker-ize. This really is a whole different ballgame, hosting on your own server. Kinda hoping the shinyapps.io will work right now.

FYI, I tried to deploy the app from RStudio into shinyapps.io, and got the same error with the pictures not displaying.

My fault. I forgot you had put it there.

Shot in the dark ....

I did notice that Swatches was not capitalized on this line but the actual directory is capitalized.
swatchfiles=list.files('./www/swatches')
My memory is fuzzy but I think Window searches are case insensitive but linux searches are case sensitive.
That might cause the app not to find any files and explain the length zero message. :man_shrugging:

1 Like

The last four digits tell us that the Shiny process is serving content on port 3838 (it was different in the first example). So something the app tried to do through there in the server.app in response to the input spawned by the ui.app is throwing the error—either because of a syntax error or logic error in server.app or server.app asked OS for something that it couldn’t/wouldn’t do. I guess there could be a process in the middle like a poorly constructed firewall. Test with a MWE with the simplest possible user input to test the OS idea. If it’s ok, the see if the server.app routine works in a non-shiny context?

That log seems to be from running the app interactively with the shiny package. This is not the same as running the app from shiny-server, they are different processes.

You can find the shiny-server logs here /var/log/shiny-server.log and the logs specific to your app inside this folder /var/log/shiny-server/

To confirm this is not an access permissions issue you could set global access for testing.

sudo chmod 777 -R /srv/shiny-server/

Thank you so much for that, I will look into it.

Well this put me on the right track! I changed all the lower case subdirectories to start with an upper case (./www/swatch -> ./www/Swatch, etc.) and was able to deploy it on shinyapps.io.

https://mckann.shinyapps.io/yurtzzle-website-shiny/

This is real progress. Now I pasted it again into the EC2 server, and am getting permissions issues? Regardless, getting it on the io is encouraging!

I will slowly digest this suggestion, thank you.

Let me look into this, thanks for your help. Might take a while to run through all these possibilities.

This is a real education. Here's the output from /var/log/shiny-server.log

[2023-01-26T17:42:07.938] [INFO] shiny-server - Shiny Server v1.5.20.1002 (Node.js v16.18.1)
[2023-01-26T17:42:07.940] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
[2023-01-26T17:42:07.981] [WARN] shiny-server - Running as root unnecessarily is a security risk! You could be running more securely as non-root.
[2023-01-26T17:42:07.986] [INFO] shiny-server - Starting listener on http://[::]:3838
[2023-01-26T17:48:36.088] [INFO] shiny-server - created bookmark state directory: /var/lib/shiny-server/bookmarks
[2023-01-26T17:48:36.088] [INFO] shiny-server - created user bookmark state directory: /var/lib/shiny-server/bookmarks/shiny
[2023-01-26T17:48:37.758] [INFO] shiny-server - Error getting worker: Error: The application exited during initialization.
[2023-01-26T18:31:36.098] [INFO] shiny-server - Stopping listener on http://[::]:3838
[2023-01-26T18:31:36.129] [INFO] shiny-server - Shutting down worker processes (with notification)
[2023-01-26T18:34:42.562] [INFO] shiny-server - Shiny Server v1.5.20.1002 (Node.js v16.18.1)
[2023-01-26T18:34:42.592] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
[2023-01-26T18:34:42.744] [WARN] shiny-server - Running as root unnecessarily is a security risk! You could be running more securely as non-root.
[2023-01-26T18:34:42.768] [INFO] shiny-server - Starting listener on http://[::]:3838

Needed resources to display are in $PATH for root?

shiny-server logs look normal to me, what about the app logs? There is where we might find a clue about what is going on

OK. I was able to make some code changes and successfully deploy it on the shinyapps.io. Now when I try to run it on the EC2 server, I am getting a different error than before in the app logs:

su: ignoring --preserve-environment, it's mutually exclusive with --login
-bash: line 1: cd: /srv/shiny-server/yurtzzle-website-shiny: Permission denied

I tried the command:
sudo chmod 777 -R /srv/shiny-server/
but it didn't fix the above Permission denied error.

And all the requirements for the app are in or under that directory?