0%

Shiny-server的安装及初步使用

安装Shiny

  1. 安装R

    sudo apt install r-base
  1. 安装Rstudio-server

    sudo apt-get install gdebi-core
    sudo apt-get install libapparmor1
    wget https://download2.rstudio.org/rstudio-server-1.0.143-amd64.deb
    sudo gdebi rstudio-server-1.0.143-amd64.deb

    因为Rstudio-server不能以root用户登录,所以我们需要创建一个用户

    sudo addusr anlan
    ......

    然后在网页上输入ip:8787进入Rstudio-server界面,输入用户和密码,即可登录

  2. 安装Shiny

    sudo su - -c "R -e \"install.packages('shiny', repos='http://cran.rstudio.com/')\""

    不能直接进入R,然后install.packages("shiny"),因为如果这样安装,是将shiny包安装下当前登录用户的个人library中,使得最终shiny-server无法运行

    sudo apt-get install gdebi-core
    wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.5.3.838-amd64.deb
    sudo gdebi shiny-server-1.5.3.838-amd64.deb

    做完以上几步后,shiny-server算是初步安装好了,然后可以在网页上52.24.111.0:3838进入shiny-server界面(52.24.111.0是ip地址)。一般我们能看到左边一列的文字和右边的两个框。当然还需要再安装个rmarkdown,不然还是会有error的

    sudo su - -c "R -e \"install.packages('rmarkdown', repos='http://cran.rstudio.com/')\""

配置Shiny Server

  1. references

    • Shiny Server log is at /var/log/shiny-server.log
    • The default Shiny Server homepage you’re seeing is located at /srv/shiny-server/index.html - you can edit it or remove it.
    • Any Shiny app directory that you place under /srv/shiny-server/ will be served as a Shiny app. For example, there is a default app at /srv/shiny-server/sample-apps/hello/, which means you can run the app by going to http://123.456.1.2:3838/sample-apps/hello/
    • The config file for Shiny Server is at /etc/shiny-server/shiny-server.conf
    • To reload the server after editing the config, use sudo reload shiny-server
    • When hosting an Rmarkdown file, name the file index.rmd and add runtime: shiny to the document’s frontmatter
  2. 赋予shiny权限

    假设当你登录是以anlan登录,你在shiny server创建的文件只有该用户(除了root)才有权限读写,但是shiny server是以shiny用户来运行shiny的app,所以要给予shiny用户在一些目录的权限。

    sudo groupadd shiny-apps
    sudo usermod -aG shiny-apps dean
    sudo usermod -aG shiny-apps shiny
    sudo chown -R dean:shiny-apps /srv/shiny-server
    sudo chmod g+w /srv/shiny-server
    sudo chmod g+s /srv/shiny-server  ####在该目录下创建的文件都属于该目录所属的组

从Git下载shiny app

  1. 下载shiny官网的例子

    git clone https://github.com/rstudio/shiny-examples.git

    文件是要下载到/srv/shiny-server中

  2. 运行例子程序

    http://52.24.111.0:3838/shiny-examples/010-download/

    想要运行哪个shiny app,只要在http://52.24.111.0:3838/后面添加/srv/shiny-server中的文件的相对路径即可

参考:

http://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/
http://www.bio-info-trainee.com/1683.html

本文出自于http://www.bioinfo-scrounger.com转载请注明出处