How to Deploy Interactive R Apps with Shiny Server 

How to Deploy Interactive R Apps with Shiny Server

Updated  , by Jared Kobos

 

 

 

What is Shiny?

Shiny is a library for the R programming language that allows you to create interactive web apps in native R, without needing to use web technologies such as HTML, CSS, or JavaScript. There are many ways to deploy Shiny apps to the web; this guide uses Shiny Server to host an example Shiny app on a Linode.

Before You Begin

If you do not have RStudio installed on your local computer, follow our How to Deploy RStudio Using an NGINX Reverse Proxy guide to set up a remote workstation on a Linode.

Build a Shiny Test App

Shiny Server comes with pre-installed demo apps. However, in order to demonstrate the process of deploying an app, you will create an app locally and deploy it to a Shiny Server on a Linode.

  1. Open RStudio and install the Shiny package:

    install.packages('shiny')
    
  2. In the File menu, under New File, select Shiny Web App…. When prompted, choose a name for your project. Select Multiple File and choose a directory to store the new app’s files.

     

     

  3. Rstudio automatically opens two new files: ui.R and server.R. These files are pre-filled with a demo app that will create an interactive histogram of R’s built-in Old Faithful data set. Edit server.R to adjust the formatting of the histogram according to your tastes. For example, to change the bars to red with a black border:

    hist(x, breaks = bins, col = 'red', border = 'black')
    
  4. To test the project locally, click Run App in the upper right corner of the text editor.

  5. Save the project and copy the files to your Linode. Replace username with your Unix account username and linodeIP with the public IP address or domain name of your Linode:

    scp -r ~/shiny/Example username@linodeIP:/home/username
    

Deploy a Shiny App to a Remote Server

The steps in this section should be completed on your Linode.

Install R

  1. Open /etc/apt/sources.list and add the following line to the end of the file:

    Ubuntu:

    deb http://cran.rstudio.com/bin/linux/ubuntu xenial/
    

    Debian:

    deb http://cran.rstudio.com/bin/linux/debian stretch-cran34/
    
  2. Add the key ID for the CRAN network:

    Ubuntu GPG key:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
    

    Debian GPG key:

    sudo apt install dirmngr
    sudo apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
    
  3. Update the repository:

    경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
    어린이용이며, 설치가 필요없는 브라우저 게임입니다.
    https://s1004games.com

    sudo apt update
    
  4. Install the R binaries:

    sudo apt install r-base
    

Add the Shiny Package

Use install.packages() to add the Shiny package:

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

Install Shiny Server

  1. Install gdebi:

    sudo apt install gdebi-core
    
  2. Download Shiny Server:

    wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.5.6.875-amd64.deb
    
  3. Use gdebi to install the Shiny Server package:

    sudo gdebi shiny-server-1.5.6.875-amd64.deb
    
  4. The shiny-server service should start automatically. Check its status:

    sudo systemctl status shiny-server.service
    
  5. In a browser, navigate to your Linode’s public IP address or FQDN on port 3838 (e.g. example.com:3838). You should see the Shiny Server welcome page:

     

     

     

Deploy Your App

By default, Shiny Server uses /srv/shiny-server/ as its site directory. Any Shiny apps in this directory will be served automatically.

  1. Copy the example app directory into /srv/shiny-server/:

    sudo cp -r Example/ /srv/shiny-server/
    
  2. In a web browser, navigate to the app’s address. Replace example.com with your Linode’s public IP address or FQDN:

    example.com:3838/Example
    

    You should see your app displayed:

     

     

     

Configure Shiny Server

Shiny Server’s configuration file is stored at /etc/shiny-server/shiny-server.conf:

File: /etc/shiny-server/shiny-server.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# 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;
  }
}

You can edit the port that Shiny Server will listen on, or change the site directory from which apps are served. The directory_index option allows visitors to view the contents of a directory by navigating to that path (for example, visiting example.com:3838/sample-apps will show a list of the example apps included in the Shiny Server installation). You can disable this behavior and hide the contents of directories by setting this option to off. For more information about configuring Shiny Server, see the official Administrator’s Guide.

After making changes to this file, restart the shiny-server service:

  sudo systemctl restart shiny-server.service

[출처] https://www.linode.com/docs/guides/how-to-deploy-rshiny-server-on-ubuntu-and-debian/

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86176
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78666
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95398
27 [java dbms][database] [컴] Apache Derby 사용하기 - 4 - in-memory DB 졸리운_곰 2021.04.15 1560
26 [java dbms][database] [컴] Apache Derby 사용하기 - 3 - Apache Derby Network Server 졸리운_곰 2021.04.15 1634
25 [java dbms][database] [컴] Apache Derby 사용하기 - 2 - sql script tool ij 사용하기 졸리운_곰 2021.04.15 1823
24 [java dbms][database] [컴] Apache Derby 사용하기 - 1 - Derby 설치 file 졸리운_곰 2021.04.15 1153
23 실습 2 - GROUP 졸리운_곰 2020.09.30 1550
22 [SQL 가이드] 데이터베이스 모델의 이해 (Understanding Database model) file 졸리운_곰 2020.06.13 2483
21 [SQL 가이드] 식별자(Identification)의 개념 file 졸리운_곰 2020.06.13 2060
20 [SQL 가이드] 관계(relationship)의 개념 file 졸리운_곰 2020.06.13 1556
19 [SQL 가이드] 속성(attribute)의 개념 file 졸리운_곰 2020.06.13 1703
18 [SQL 가이드] 엔티티의 개념 file 졸리운_곰 2020.06.13 2201
17 [SQL] join의 on절과 where절 차이 졸리운_곰 2020.05.16 1304
16 JOIN*(3개 테이블) and GROUP BY*(보이지않더라도 key칼럼으로) and ORDER BY 졸리운_곰 2020.05.16 1224
15 다중 테이블에서 데이터 검색 - JOIN file 졸리운_곰 2020.05.16 1596
14 IFNULL(MYSQL), ISNULL(MSSQL), NVL(ORACLE) 졸리운_곰 2018.07.24 1778
13 4 Ways to Join Only The First Row in SQL file 졸리운_곰 2018.07.03 1637
12 DBMS별 기존테이블 SELECT해서 새 테이블에 INSERT하여 데이터 ... file 졸리운_곰 2018.01.22 1592
11 SOL 개발자의 현주소 : 개발자가 SQL 작성시 고쳐야 하는 태도 file 졸리운_곰 2018.01.01 2159
10 오라클 운반 최소 단위 BLOCK file 졸리운_곰 2017.07.15 2035
9 재미있는 DB 이야기 ‘놀라운 마방진의 세계’ file 졸리운_곰 2017.07.15 2394
8 재미있는 DB 이야기 ‘사라진 날짜를 찾아라’ file 졸리운_곰 2017.07.15 2224
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED