-
Notifications
You must be signed in to change notification settings - Fork 0
Howto Install Shiny Server on OSX
I want to set up the shiny-server to run on Nauru so that we can run multiple R-apps over the web. According to the docs for Shiny server, OSX is not supported yet (version 1.1.0) so we are going to build it from source and hope for the best!
Instructions for building from source are here. We follow them pretty closely but there are a few gotchas.
-
First we need to update our environment and get some prerequisites out of the way.
# R is already installed via Homebrew, as is the shiny package for R # Remember we are using virtual environments on this machine brew update brew install cmake -
Next, get the
shiny-servercodegit clone https://github.com/rstudio/shiny-server.git -
Next, we need to build the server, but before we compile it, we need to make some edits to one of the C files or it will not actually launch the server after you build it.
cd shiny-server mkdir tmp cd tmp DIR=`pwd` PATH=$PATH:$DIR/../bin/ PYTHON=`which python` # Python version must be 2.6.x or 2.7.x ONLYAt this point, we need to edit the file
src/launcher.cc
Make all of the edits to the file that are contained in this gist (original commit link is here )cmake -DCMAKE_INSTALL_PREFIX=/usr/local/var -DPYTHON="$PYTHON" ../ make mkdir ../build (cd .. && ./bin/npm --python="$PYTHON" install) (cd .. && ./bin/node ./ext/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js --python="$PYTHON" rebuild) sudo make install
We will be using the default configuration files and settings for most things
-
Place a shortcut to the shiny-server executable in
/usr/bin. With OS X El Capitan and later you have to disable System Integrity Protection (SIP) first. Do this by rebooting your mac into Recovery Mode by restarting and holding down Command+R until the logo appears. Open a terminal from the Utilities menu and type "csrutil disable", reboot and then execute the command below. Don't forget to turn on SIP again immediately after, using the same procedure, but now with "csrutil enable" in the terminal.sudo ln -s /usr/local/var/shiny-server/bin/shiny-server /usr/bin/shiny-server -
Create the shiny user that the server will run under. The instructions call for
useraddbut that doesn't exist in OSX, so we will have to manually do it withdsclsudo dscl . -create /Users/shiny sudo dscl . -create /Users/shiny Password "shiny" sudo dscl . -create /Users/shiny UserShell /bin/sh sudo dscl . -create /Users/shiny Realname "Shiny Server" sudo dscl . -create /Users/shiny PrimaryGroupID "80" sudo dscl . -create /Users/shiny UniqueID "502" sudo dscl . -create /Users/shiny NFSHomeDirectory "/Users/shiny"It may be necessary to go into
System Preferences/Users & Groups/GUI and change the password for the shiny user. You must be able tosuto the shiny user before continuing. -
Create Log, config and application directories
sudo mkdir -p /var/log/shiny-server sudo mkdir -p /srv/shiny-server # This is the applications directory, all apps go here sudo mkdir -p /var/lib/shiny-server sudo chown shiny /var/log/shiny-server sudo mkdir -p /etc/shiny-server -
Test the server. At this point you should be able to start the server and serve an app if you put one in the application directory.
sudo su shiny -c shiny-server [2014-02-19 10:03:45.125] [INFO] shiny-server - Shiny Server v1. 1. 0.0 (Node.js v0.10.21) [2014-02-19 10:03:45.128] [INFO] shiny-server - Using config file "/usr/local/var/shiny-server/config/default.config" [2014-02-19 10:03:45.180] [INFO] shiny-server - Starting listener on 0.0.0.0:3838 # Access the server on port 3838Success!!
Okay, the server works and your application works, now we need to be served as a daemon so we don't have to worry about it any more.
-
Create a plist file in
/Library/LaunchDaemonscalledcom.xoma.shiny-server.plistthat looks like this<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Disabled</key> <true/> <key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/local/bin/</string> </dict> <key>GroupName</key> <string>admin</string> <key>KeepAlive</key> <true/> <key>Label</key> <string>com.xoma.shiny-server</string> <key>Program</key> <string>/usr/bin/shiny-server</string> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>shiny</string> <key>WorkingDirectory</key> <string>/usr/local/var/shiny-server</string> </dict> </plist> -
Start the server with
sudo launchctl load -w /Library/LaunchDaemons/com.xoma.shiny-server.plist