Skip to main content

How To Install R and R Studio Server On Centos

How To Install R and R Studio Server On Centos

R is extensively used for data processing and analyzing. R has gained lot of popularity over the last few years because of data explosion over the mobile and web applications.

To leverage the power of R and its eco system, one needs to have complete R suite of tools installed. Although there is large community of R developers and system administrators, I couldn't find a good resource where I could find everything about installing R and its tools in simple easy steps. That's why I decided to write this post. In this post, I will talk about installing following...
  1. R
  2. R Studio Server
  3. R Studio Connect

Install R

Please run following two commands to install R.

sudo yum install epel-release
sudo yum install R

Type R -verson in your bash shell. You should see following output depending upon what version of R you have.

To Bring up the R repl. Just type R and you should have your R shell started. To install any package in R, just do install.packages("<package_name>") inside the R repl. For example to install tidyverse which is very popular data maniuplation R package, just type following and command and hit enter.

install.packages("tidyverse")

R will install in to /usr/lib64/R/library.

Install R Studio Server

R Studio is a very powerful software for writing R scripts and also for building R applications. R studio has cloud version too which once installed can be accessed over any web browser. To install R studio server on centos, go to https://rstudio.com/products/rstudio/download-server/redhat-centos/ link and copy and paste the installation commands based on your Centos version. I have Centos 7.

wget https://download2.rstudio.org/server/centos6/x86_64/rstudio-server-rhel-1.3.1056-x86_64.rpm
sudo yum install rstudio-server-rhel-1.3.1056-x86_64.rpm

Ok the above will install the R studio server. To check the installation, run following command in your bash shell...

rstudio-server  verify-installation

If you see the following message, it means R server is installed properly and it is running fine.
Server is running and must be stopped before running verify-installation

By default, R studio is available on port 8787.
http://localhost:8787/auth-sign-in
Go to the above link and you should see following screen.
Note: If you want to access the R studio over an IP address. You need to open the port 8787.
Rstudio Server Authentication: By default, PAM authentication is enabled. Therefore use the same user name and password that you used to login to use Centos machine.

Once you login, you should see R studio opened in your browser.

Install R Studio Connect

R studio Connect helps you publish Shiny apps over the web. 
Go to link https://rstudio.com/products/connect/download-commercial/redhat-centos/ and run following commands based on your Centos version. For Centos 7 run following commands.

curl -LO https://cdn.rstudio.com/connect/1.8.4/rstudio-connect-1.8.4-11.el7.x86_64.rpm
sudo yum install rstudio-connect-1.8.4-11.el7.x86_64.rpm

Above commands will install the Rstudio-connect. To start rstudio-connect, run following command.


service rstudio-connect start



Rstudio-connect has multiple ways to setup authentication. The easiest one is PAM. To enable PAM authentication look for following config file

/etc/rstudio-connect/rstudio-connect.gcfg

Open the above file in your favorite editor and change Provider = pam.

[Authentication]
; Specifies the type of user authentication.
Provider = pam

Now restart the service again.

service rstudio-connect start



Ok now the rstudio-connect is installed and running successfully.  To publish R shiny apps from the R studio server using rstudio-connect, we need to add the account to R studio. To do that, go to your Rstudio and load your Shiny app. Now to button which is right next to "run apps", click on it and choose "other destinations'

In the new pop up window, choose the option "Add New Account"


Then choose option "Rstudio Connect"

Add your ip or domain address


Once you do that, click on "Connect". This will open up Rstudio-Connect pop up for authentication. Fill in your PAM login and password informtion. After successful authentication the screen in Rstudio will change to following...


Click on "Connect Account" You would your other screen "Rstudio Connect" will change with congratulation message. That means you have successfully connected the Rstudio Connect with Rstudio.
Now in Rstudio, go to the blue icon again which is right next to "Run app" and choose your R shiny app to publish. A new pop up will show up asking you to choose the account to publish the app. Choose your newly activated Rstudio connect account.  You would see your browser directing you to following link...

Note: If you are using your domain or Ip address, you need to open up the port 3939.

Wrap Up

I hope you would find the above post useful for installing R and R tools. 





Comments