1

I have an R script, a Shiny app to be specific that lives on a network drive. There are multiple computers that need to be able to run this app, and therefore multiple people who may need to run it at the same time.

For the moment, I have gotten around the problem simply by housing multiple duplicate Shiny apps, and giving each computer access to a unique copy. However, as the number of users expands, it is becoming more and more difficult to keep up with.

Is there a way to have multiple computers access the same R script at the same time, and hold open a session for however long they need?

5
  • Is the problem that multiple computers are accessing the same source files on a network drive? If so, create a git repo with your source files and clone the git repo onto each computer. Is the problem accessing the same data? Then a database would be a good way to go. Commented May 31, 2017 at 16:41
  • The problem is that multiple computers are accessing the same source files. Getting the data isn't a problem, since it lives on a SQL database and is queried dynamically as the user interacts with the app. Git repo may be the way to go. How could I go about setting that up? That would mean I would only need to clone it once on each computer? I do not have much experience with git. Thanks. Commented May 31, 2017 at 16:50
  • Option C: create an R package (i.e. a directory with a bit of structure) on the network drive and use devtools::install("path/to/my/code") to install the Shiny app onto each computer. Hadley Wickham's excellent guide to building R packages has more on that solution (this is more R specific and probably a bit more of an investment than git) Commented May 31, 2017 at 16:50
  • 2
    Crikey, just install shiny server. Commented May 31, 2017 at 16:55
  • Issue with shiny server is that this app contains sensitive data, and I can't risk anything other than deploying it on the in-house network drive. Commented May 31, 2017 at 17:03

2 Answers 2

2

If you go with the R package route, and:

  • you want you're user's to know when their package is out of date
  • your package code is in a git repo (always a good idea)
  • your users install the package using devtools::install_git("path/to/package/git/repo")

then you can add these lines to your package's .onload() method (documented here and here: ?.onLoad):

# Check if the package is up to date
pd <- packageDescription(pkgname)
out_of_date_message_template <- 
    'Your copy of package %s is not up to date.\nUse devtools::install_git("%s") to update this package\n'
if(identical(pd$RemoteType,"git")){
    try({
        # get the hash of the remote repo
        out_file <- tempfile()
        on.exit(unlink(out_file))
        failed <- system2("git",sprintf('ls-remote "%s"',pd$RemoteUrl),stdout = out_file)
        if(failed)
            return() # failed to get the git repo hash
        remotes <- readLines(out_file)
        if(!identical(pd$RemoteSha,gsub("\t.*","",remotes[1])))
            packageStartupMessage(
                  sprintf(out_of_date_message_template,
                          pkgname,
                          gsub("\\\\","\\\\\\\\",pd$RemoteUrl)))
    })
}

then when you push an update to your network git repo, users with out of date code will get this message when they call library(my_app)

Your copy of package my_app is not up to date.
Use devtools::install_git("path\\to\\package\\git\\repo") to update this package
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help! this is great. I will proceed with this, and see if I can work something out where it installs the update automatically instead of prompting the user to do so.
0

Once you have git installed on your local computer, initialize the repo on the network drive like this:

cd my/network/shiny-app
git init
git add .
git commit -m "initial commit"

Then on each computer,

cd some/place/nice
git clone my/network/shiny-app
cd shiny-app
ls  # hey look- all my files are now in this directory!

There are plenty of good git tutorials on the internets for when you decide to update your code and need to pull it to each computer.

4 Comments

Thank you very, very much. This is helpful. From what I know about git, does this mean that each user will need to do a git pull whenever I release an update?
Yep. Likewise, if you go with the R package, everyone will need to do a devtools::install(...) with every update. Shiny server may be less of a headache if that solution works for you.
I see. The idea is that the app will be expanded to many people (30+) who may not be very tech savvy. Right now, the way that I have it, everyone has a shortcut to an R script on the network drive, so when I update I just need to replace the R script and the user would not even know that the app has been updated, it just works. That's why I thought if there's a way for many computers to hold open the same R script, I could go for that. I'm uncertain about the security of Shiny Server as this app has access to sensitive data. Is there a way to make this work, or is it not entirely possible?
I suppose if I go the R package route, I might be able to add a couple of lines at the top that check for an update and install it if that returns TRUE. Might that be a possibility?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.