Strange Working Directory Behavior after Shiny Deploy

759 views
Skip to first unread message

Mike Mehan

unread,
Jul 15, 2016, 9:04:00 PM7/15/16
to Shiny - Web Framework for R
I just got done wrestling with some very strange shiny server behavior and I was wondering if anyone could explain it to me. Here's what happened:


I developed a shiny app locally. I had some data that was loaded from a data directory and some stuff in globals.R shared by the ui.R and server.R. I initially deployed my app to my local install of shiny server. Then I made some changes and decided that I should have deployed using svn rather than just copying over the files. I moved the existing folder containing my shiny app to a new folder called archive and then replaced the directory I had just created by checking out the new version from my svn repo. This is when I noticed things started to go wrong, but I had no idea what was causing it. Suddenly variables that I had created in my global.R file weren't being recognized on the server. The app worked perfectly fine on my local machine, then I would deploy via svn and it was like it wasn't reading my global.R properly. So I rewrote the app using renderUI instead of using globals and then I noticed it wasn't registering any changes to my data directory, which was populating the dashboard. It seemed like everything was out of sync. After a lot of debugging I finally printed the working directory of my server-side R session and I noticed that it was set to the archive folder I had made when cleared the way for the svn deploy. Then I tried moving this archive folder into my home directory and sure enough, the shiny app switched over to ~/archive. It was loading server.R and ui.R from the proper place /srv/shiny-server/appName, but the R working directory was following around the shiny app that was originally at that location. I can't wrap my head around how that would happen and was hoping someone smarter could break it down for me.

I realize that ran sort of long so here's a shorter list of steps:
  1. Deployed app on shiny server by copying ui.R, server.R, global.R, and data_dir to /srv/shiny-server/appName
  2. Renamed /srv/shiny-server/appName to /srv/shiny-server/archive
  3. Redeployed app on shiny server using svn, to original location: /srv/shiny-server/appName
  4. Noticed changes to global.R and contents of data_dir weren't being recognized. All changes to server.R and ui.R were recognized though
  5. Printed out R working directory using shinyjs and noticed it was /srv/shiny-server/archive, the original deployment directory
  6. Moved the original deploy again, and the working directory followed it
  7. Restarted shiny server and problem went away

The whole time I was pointing to the same URL. Glad that I finally got it figured out, because it was driving me crazy all day. I did get to learn how to use renderUI so something good came out of it. If anyone can provide any insight that would be great.

Joe Cheng

unread,
Jul 16, 2016, 12:41:08 AM7/16/16
to Mike Mehan, Shiny - Web Framework for R
The problem basically is that Shiny sets its working directory (setwd) once on process startup, and you can think of it being "in" that directory from then on. If you move the directory, it doesn't matter to the R process that Shiny is running in--it moves with it. Only restarting the R process (which by default happens 5 seconds after the last user of that particular app disconnects), which you finally did when you restarted shiny-server, makes the app pick up the new directory at the original path.

I was having trouble imagining how to work around this, but you say that getwd() returns the new path after the directory is moved? This may be a helpful clue... we can try to call setwd if we notice an unexpected change in getwd.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/7b1a89f1-ed0a-40e5-ab63-fba035a7d405%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Barry DeCicco

unread,
May 17, 2017, 6:02:59 PM5/17/17
to Shiny - Web Framework for R, mme...@gmail.com
Hello,

I'm observing this behavior locally - I ran the example "01_hello" from lesson 1 in the RStudio tutorial (http://shiny.rstudio.com/tutorial/lesson1/) and now even if I explicitly invoke another app,
it loads the "01_hello"  app.  When I modified the files, it opened the original files; when I eliminated the files and the directory, it *still* opens them, somehow.

I've restarted RStudio several times, and the behavior persists. 

Does anybody know a method of getting it to behave better?

Sincerely,

Barry

Joe Cheng

unread,
May 18, 2017, 1:51:16 AM5/18/17
to Barry DeCicco, Shiny - Web Framework for R, mme...@gmail.com
That's strange. What specific action are you referring to when you say "invoke another app"? Or in general what are the steps we should try to reproduce this?

Joe Cheng

unread,
May 18, 2017, 12:41:14 PM5/18/17
to Barry DeCicco, Barry DeCicco, Shiny - Web Framework for R, mme...@gmail.com
The "ERROR: [on_request_read] connection reset by peer" is just a notification that a client (browser) closed a network connection without saying goodbye--you can safely ignore it.

Under no circumstances should "library(shiny)" launch any app--you literally typed that into the console, pressed Enter, and an app launched?

On Thu, May 18, 2017 at 8:28 AM Barry DeCicco <bdecic...@yahoo.com> wrote:
Joe, 

Thanks for getting back to me!

I started from scratch, uninstalling the shiny package, and removing the RStudio project folder.    I was unable to duplicate the error; things generally ran well.
I was forced to update shiny, but that was after I got it to run correctly.

I did run into two new errors:

1)  I got the error "ERROR: [on_request_read] connection reset by peer", but the app ran, and a window opened normally. 

2)  At one point, no app ran.  There were no error messages, but no results.  I re-ran the command 'library(shiny)'.  This launched the previous app.  When I closed that, subsequent apps ran correctly.

Sincerely,

Barry



From: Joe Cheng <j...@rstudio.com>
To: Barry DeCicco <decicc...@gmail.com>; Shiny - Web Framework for R <shiny-...@googlegroups.com>
Cc: mme...@gmail.com
Sent: Thursday, May 18, 2017 1:51 AM
Subject: Re: Strange Working Directory Behavior after Shiny Deploy
Reply all
Reply to author
Forward
0 new messages