LoginSignup
0
0

More than 3 years have passed since last update.

【R】Shiny-Serverのインストール

Last updated at Posted at 2020-01-27

ことの顛末

Shinyを使うシーンとして、RStudioで使うことが多いようですが、自分としてはwebサーバ上で使いたいのです。
phpをメインで利用しているので、phpで作られたシステムから収集されるDB情報を元に統計などをグラフ化するために挑戦しています。
いきなり会社のサーバに入れる勇気は絶対ないので、まずはVirtualBoxや自前のvpsで使えるようになってからです。

※この記事は、先日出来ない出来ないと嘆いてた時の記事を削除して、書き直したものです。

環境

・さくらvps
・CentOS7.7
・R3.6

Rのインストール

shiny-serverのインストール

[root@localhost ~]# yum -y install readline-devel 
[root@localhost ~]# yum -y install libXt-devel 
[root@localhost ~]# yum -y install Xvfb
#上三つはいらないかも知れない
[root@localhost ~]# yum -y install libcurl-devel
[root@localhost ~]# sudo su - -c "R -e \"install.packages(c('shiny', 'rmarkdown'), repos='http://cran.rstudio.com/')\""
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core) #当方の環境
[root@localhost ~]# wget https://download3.rstudio.org/centos6.3/x86_64/shiny-server-1.5.12.933-x86_64.rpm
[root@localhost ~]# yum -y install --nogpgcheck shiny-server-1.5.12.933-x86_64.rpm
[root@localhost ~]# systemctl start shiny-server
[root@localhost ~]# systemctl enable shiny-server

Shinyの設定ファイル(後でこれを復元します)

[root@localhost ~]# cat /etc/shiny-server/shiny-server.conf
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# 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;
  }
}

[root@localhost ~]# firewall-cmd --add-port=3838/tcp --permanent
[root@localhost ~]# firewall-cmd --reload
[root@localhost ~]# systemctl restart shiny-server
[root@localhost shiny-server]# /opt/shiny-server/bin/deploy-example user-dirs
Configuration file already exists at /etc/shiny-server/shiny-server.conf. Are you sure you want to overwrite it? [yN]y
Copied /opt/shiny-server/config/user-dirs.config to /etc/shiny-server/shiny-server.conf.
Installing sample apps...
/srv/shiny-server/index.html already exists. Not overwriting.
/srv/shiny-server/sample-apps already exists. Not overwriting.
Done installing samples.
Restarting Shiny Server...
Waiting...

The user-dirs config is all setup now. Enjoy!

上記を実行するとconfファイルが初期化されて動かない状態になる。
もう少し上に書いたconfファイルではなくなるので、元に戻す。
まだ試してないけどuser-dirsの部分で引数をもっと入れれば最初から動かせるようになるのかも知れない。

ip:3838へブラウザでアクセス

00000200632.JPG
画像は127.0.0.1になっていますが、VirtualBoxで試した時の画像なので勘弁してください(;´Д`)
ポート番号3838はデフォルトのものではなく、変えて利用しましょう。

戯言

phpを混ぜられたらいいなぁ・・・ダメですよねきっと(´・ω・`)
本当はゲットパラメーターで値を引き渡したいのですが、無理だと思うので考えます。。
元システムからのリンクを全部別個のhtmlファイルで作成して、そのアドレスによってアプリが変わるとか?
phpで遷移する時特定のページへ遷移させて、そこで取得したPOSTの値をjsonファイルに書き込んでからRのURLに遷移させて、そのjsonファイルを読み込んでRで処理するとか?
jsonじゃなくてもいいか。user_app.Rみたいなファイルにrプログラムを自動で生成するphpのスクリプトを書いて、それをR側でrequireみたいなことすれば出来そうか。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0