install Shiny Server :: Ubuntu
http://statkclee.github.io/raspberry-pi/iot-rstudio-shiny.html
https://www.r-bloggers.com/deploying-your-very-own-shiny-server/
http://docs.rstudio.com/shiny-server/
https://www.rstudio.com/products/shiny/download-server/ – 다운로드
Open Source Shiny Server는 한 서버에 여러개의 Shiny application을 hosting할수 있는 platform을 제공한다.
building on non-supported distributions , Administrator’s Guide 을 참조
설치 전 확인
1. R 설치 확인
R는 당연히 설치되어 있어야 한다.
⇒ R --version
2. Shiny package 설치
(Shiny 서버 설치전) R에 Shiny 팩키지 설치
Ubuntu
방법1
sudo R > .libPaths() [1] "/usr/local/lib/R/site-library" [2] "/usr/lib/R/site-library" [3] "/usr/lib/R/library" > install.packages('shiny', lib=.libPaths()[1])
방법2
sudo su - -c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/', lib=.libPaths()[3])\""
Installing package into ‘/usr/lib/R/library’ (as ‘lib’ is unspecified) also installing the dependencies ‘Rcpp’, ‘httpuv’, ‘mime’, ‘jsonlite’, ‘xtable’, ‘digest’, ‘htmltools’, ‘R6’, ‘sourcetools’
방법3 (local)
$ sudo su - -c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
cf. HTTPS에 문제가 있는 경우 CRAN mirror를 사용
$ sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.nexr.com/')\""
확인
3. rMarkdown package 설치(option)
$ sudo su - -c "R -e \"install.packages('rmarkdown', repos='http://cran.nexr.com/')\""
Shiny server 설치
https://www.datascienceriot.com/install-shiny-server-for-r-on-ubuntu-the-right-way/kris/
https://www.rstudio.com/products/shiny/download-server/ – 다운로드
다운로드
deb파일 실행으로 위해 gdebi-core를 먼저 설치하고,
$ sudo apt-get install gdebi-core
보안으로 인해 다운이 안될 경우, -no-check-certificate
옵션을 맨뒤 사용.
$ sudo wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.5.4.869-amd64.deb
설치
다운받은 deb파일 실행하여 설치
$ sudo gdebi shiny-server-1.5.1.834-amd64.deb
Reading package lists... Done Building dependency tree Reading state information... Done Reading state information... Done Shiny Server Shiny Server is a server program from RStudio, Inc. that makes Shiny applications available over the web. Shiny is a web application framework for the R statistical computation language. Do you want to install the software package? [y/N]:y Selecting previously unselected package shiny-server. (Reading database ... 290828 files and directories currently installed.) Preparing to unpack shiny-server-1.5.1.834-amd64.deb ... Unpacking shiny-server (1.5.1.834) ... Setting up shiny-server (1.5.1.834) ... Creating user shiny Adding LANG to /etc/systemd/system/shiny-server.service, setting to en_US.UTF-8 Created symlink from /etc/systemd/system/multi-user.target.wants/shiny-server.service to /etc/systemd/system/shiny-server.service. ● shiny-server.service - ShinyServer Loaded: loaded (/etc/systemd/system/shiny-server.service; enabled; vendor preset: enabled) Active: active (running) since 수 2017-01-25 16:27:24 KST; 30ms ago Process: 25797 ExecStartPost=/bin/sleep 3 (code=exited, status=0/SUCCESS) Main PID: 25800 (shiny-server) CGroup: /system.slice/shiny-server.service ├─25795 /bin/bash -c /opt/shiny-server/bin/shiny-server --pidfile=/var/run/shiny-server.pid >> /v... └─25800 /opt/shiny-server/ext/node/bin/shiny-server /opt/shiny-server/lib/main.js --pidfile=/var/... 1월 25 16:27:21 eos systemd[1]: Starting ShinyServer... 1월 25 16:27:24 eos systemd[1]: shiny-server.service: Supervising process 25800 which is not our chil...xits. 1월 25 16:27:24 eos systemd[1]: Started ShinyServer. Hint: Some lines were ellipsized, use -l to show in full.
설치 확인
$ sudo systemctl status shiny-server
http://localhost:3838/
http://192.168.56.1:3838/sample-apps/hello/
https://www.datascienceriot.com/install-shiny-server-for-r-on-ubuntu-the-right-way/kris/
sudo chmod -R 777 /srv
Configure
/etc/shiny-server shiny-server.conf
# Instruct Shiny Server to run applications as the user "shiny" run_as sool; # Define a server that listens on port 3838 server { listen 3838; # Define a location at the base URL location / { # Host the directory of Shiny Apps stored in this directory site_dir /srv/shiny-server; # Log all Shiny output to files in this directory log_dir /var/log/shiny-server; # When a user visits the base URL rather than a particular application, # an index of the applications available in this directory will be shown. directory_index on; } }
/etc/shiny-server shiny-server1.conf
listen 3838; # Log all Shiny output to files in this directory log_dir /var/log/shiny-server1;
/etc/shiny-server shiny-server2.conf ……
listen 4848; # Log all Shiny output to files in this directory log_dir /var/log/shiny-server2;
/etc/shiny-server shiny-server6.conf ……8888
Install Dependencies and Packages Needed by Shiny Server
We’re going to need the devtools package,
which means we need to install the libraries upon which it depends first (libcurl and libxml2):
$ sudo apt-get -y build-dep libcurl4-gnutls-dev $ sudo apt-get -y install libcurl4-gnutls-dev $ sudo apt-get -y build-dep libxml2-dev $ sudo apt-get -y install libxml2-dev
Shiny server 관리
systemctl stop shiny-server.service 2>/dev/null systemctl start shiny-server.service
RHOME link만들기
⇒ sudo ln -s /Users/onesixx/Dropboox/RHome/ /srv/shiny-server/rhome
http://10.144.66.114/shiny/index.html
http://10.144.66.114/shiny/rhome/
?
/opt/shiny-server/bin/deploy-example
#!/bin/bash if [ "$(id -u)" != "0" ]; then echo "You must be root to run this script." exit 1 fi if [ $# -gt 0 ]; then CONF=$1 if [ $CONF == "shiny-server-rules" ]; then echo "shiny-server-rules is not a valid configuration." exit 1 fi else # No arguments passed. Use the default. CONF="default" fi echo "Attempting to deploy configuration named: $CONF" FILE="/opt/shiny-server/config/$CONF.config" if [ ! -f $FILE ]; then echo "ERROR: There is no configuration named: $CONF" exit 1 fi SSCONF="/etc/shiny-server/shiny-server.conf" # Restart restart_shiny () { echo "Restarting Shiny Server..." INIT_SYSTEM=`cat /proc/1/comm` if test $INIT_SYSTEM = "systemd" then systemctl stop shiny-server.service 2>/dev/null echo "Waiting..." systemctl start shiny-server.service elif test -d /etc/init/ then initctl stop shiny-server 2>/dev/null echo "Waiting..." initctl start shiny-server else /sbin/service shiny-server stop 2>/dev/null echo "Waiting..." sleep 5 /sbin/service shiny-server start fi echo echo "The $CONF config is all setup now. Enjoy!" } copy_config () { /bin/cp -f $1 $SSCONF echo "Copied $1 to $SSCONF." echo "Installing sample apps..." if [ ! -e /srv/shiny-server/index.html ]; then ln -s /opt/shiny-server/samples/welcome.html /srv/shiny-server/index.html echo "Created /srv/shiny-server/index.html" else echo "/srv/shiny-server/index.html already exists. Not overwriting." fi if [ ! -e /srv/shiny-server/sample-apps ]; then ln -s /opt/shiny-server/samples/sample-apps /srv/shiny-server/sample-apps echo "Created /srv/shiny-server/sample-apps/" else echo "/srv/shiny-server/sample-apps already exists. Not overwriting." fi echo "Done installing samples." restart_shiny } if [ -f $SSCONF ]; then read -p "Configuration file already exists at /etc/shiny-server/shiny-server.conf. Are you sure you want to overwrite it? [yN]" -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then copy_config $FILE else echo "Not overwriting existing file. Exiting." exit 1 fi else copy_config $FILE fi
/opt/shiny-server/bin/node
#!/bin/sh dir=`dirname "$0"` exec "$dir/../ext/node/bin/node" "$@"
/opt/shiny-server/bin/npm
#!/bin/sh dir=`dirname "$0"` exec "$dir/../ext/node/bin/node" "$dir/../ext/node/lib/node_modules/npm/bin/npm-cli.js" "$@"