© Matt Wiley and Joshua F. Wiley 2016

Matt Wiley and Joshua F. Wiley, Advanced R, 10.1007/978-1-4842-2077-1_12

12. Cloud Ubuntu for Windows Users

Matt Wiley and Joshua F. Wiley1

(1)Elkhart Group Ltd. & Victoria College, Columbia City, Indiana, USA

As you saw in the last chapter, using the cloud does not always allow for using Windows. This is not entirely true; Windows can certainly be utilized in the cloud. However, this tends to approximately double the cost in high-performance environments, making it impractical for some occasions. Additionally, it is not impossible to use the Ubuntu environment, and many of the same skills advanced R users have translate readily. All in all, using Ubuntu as your server instance operating system is not difficult with a little guidance to get started.

Our goals for this chapter include understanding the basic Ubuntu command line, updating and installing any operating system or packages required, installing both R and RStudio Server, and using R on both the command line and via the server. In particular, you’ll learn how to get an R process running on the server regardless of whether it’s connected to that server. Thus, we can use PuTTY to check in as needed (along with AWS warning signals) to detect when a process has finished.

Common Commands

Several of the commands we use in Ubuntu have counterparts in R. Others are more operating system specific rather than program specific. Many of the techniques we use to manage files in R can be done faster and more naturally via the command line. In this section, we explore the usual sorts of commands that are helpful to know and understand.

The first useful command is clear, a counterpart to Ctrl+L in R. This clears your viewing screen and allows you to easily see current commands and their results. We pair this command with ls, which is the list directory comments command. Right away the file we uploaded in the last chapter ch02_link.txt shows up.

clear              
ls
ch02_link.txt

Now that we can see which files are in our directory, let’s get a little bit more information about those files. The ls command can be modified with several letters. The -l modification is the long format, and it gives information about the file rights (-rw-rw-r--), about the user and the user group (both ubuntu, as we have a simple user set up currently), file size, as well as the date modified (notice this preserved our file’s original modified date from before we uploaded it). Of particular note is the usage of file rights that relate to file security and safety. In Unix systems such as Ubuntu, all objects come with rights. The pattern is -ooogggppp-, where o refers to file owner, g relates to the group membership of the owner, and p is for public. Furthermore, each level of user can either Read, Write, or eXecute a particular object. This becomes quite important later, when we create some public-facing utilities that are accessible from the Web. It is important that we check the permissions, to ensure that the public can read files, yet not write or modify them. In our code that follows, both the user ubuntu as well as any future members of the group ubuntu are allowed both read and write access to our text file. The general public, if this directory were ever made public, would be able to only read our file.

ls -l              
total 4
-rw-rw-r-- 1 ubuntu ubuntu 14 Feb 14 05:16 ch02_link.txtCloud Ubuntu, Windows userscommands

We said the word directory, so we may as well see where we live in our system. Folders, or directories, also come with the same access permissions (they are objects), and we can create new directories and change directories. To present the working directory, we use pwd; to make a directory, we use mkdir; and to change the directory, we use cd. We show these commands and their results in the code that follows. Note that the .. command returns us one level up in the directory structure, back to our original user directory.

pwd                
/home/ubuntu


mkdir MyFolder
cd MyFolder
ubuntu@ip-10-0-0-244:∼/MyFolder$ pwd
/home/ubuntu/MyFolder


ubuntu@ip-10-0-0-244:∼/MyFolder$ cd ..
ubuntu@ip-10-0-0-244:∼$

Having discussed making and navigating directories, we turn our attention to removing files. To remove a file, we use the command rm. We go ahead and do that to our text file that we uploaded; there was never any need for it other than as an example file. We show the removal in the following code, along with a full view of our user folder. Showing our list command with the full view allows us to see that our text file has been removed in the before and after views.

ls -hl                
total 8.0K
-rw-rw-r-- 1 ubuntu ubuntu   14 Mar 16 02:29 ch02_link.txt
drwxrwxr-x 2 ubuntu ubuntu 4.0K Mar 16 14:09 MyFolder


rm ch02_link.txt
ls -hal
total 4.0K
drwxrwxr-x 2 ubuntu ubuntu 4.0K Mar 16 14:09 MyFolder

The values of these access permissions may be modified. The command chmod takes three number inputs after it in the pattern chmod ogp. We create a file and give three levels of access to the user, to the user’s group, and to the public. Execute permission is given by 1, write is provided by 2, and read is given by 4. Additionally, numbers may be added to give more permission. See the example that follows: 7 = 1 + 2 + 4 gives the user full access, and 6 = 2 + 4 gives the group read and write access only. Finally, the public has only write access.

touch permissionsFile              
ls -hl
total 4.0K
drwxrwxr-x 2 ubuntu ubuntu 4.0K Mar 16 14:09 MyFolder
-rw-rw-r-- 1 ubuntu ubuntu    0 Mar 16 15:38 permissionsFile
chmod 762 permissionsFile
ls -hl
total 4.0K
drwxrwxr-x 2 ubuntu ubuntu 4.0K Mar 16 14:09 MyFolder
-rwxrw--w- 1 ubuntu ubuntu    0 Mar 16 15:38 permissionsFile

We end this section discussing two terminal commands, sudo and whoami. In the next section, we are going to start updating and maintaining our operating system. This requires root-level privileges. For security, our Ubuntu instance does not have a permanent root user, exactly. Instead, when we need elevated privileges, we give them to our ubuntu user by prefacing a command with sudo. This command stands for superuser do and is always followed by another command. The system temporarily escalates privileges for the command that follows.

whoami                
ubuntu


sudo whoami
root

Now that we have the ability to run various commands as root, we turn to the next section, where we make sure that our cloud instance is up-to-date with the latest patches and packages.

Superuser and Security

Just as in any operating system and software suite, often updates should occur. Some may add new or improved functionality, while others may be more security related. While comprehensive cloud and server security is far beyond the scope of this text, a few steps make sense to do directly. Looking at Figure 12-1, it is clear we have some work to do.

A393929_1_En_12_Fig1_HTML.jpg
Figure 12-1. The first screen shows 33 security updates

The update process involves three steps. We first run sudo apt-get update with the following abbreviated code output:

sudo apt-get update              
....
Fetched 3,451 kB in 3s (1,097 kB/s)
Reading package lists... Done

Next, we upgrade our current files so that we are ready to install new ones if we so desire. This takes some time, as we have quite a few to download! Again, we abbreviate some of the output. Of interest is to note that we did agree to continue when asked.

sudo apt-get upgrade              
Reading package lists... Done
Building dependency tree
Reading state information... DoneCloud Ubuntu, Windows userssuperuser and security
Calculating upgrade... Done
....
62 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Need to get 23.5 MB of archives.
After this operation, 209 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
....done.

Now that our files are upgraded, we can install our new packages. We run the command sudo apt-get dist-upgrade at the command line, agreeing to the prompts when asked. While it is not necessarily required, we also reboot the system. This exits us from our session, and we have to re-access our cloud via PuTTY. We show both the abbreviated code to perform these commands as well as the Figure 12-2 screenshot showing no more updates possible.

A393929_1_En_12_Fig2_HTML.jpg
Figure 12-2. Ubuntu startup screen showing no needed updates or upgrades
sudo apt-get dist-upgrade                
...
sudo reboot
ubuntu@ip-10-0-0-244:∼$
Broadcast message from ubuntu@ip-10-0-0-244
        (/dev/pts/0) at 16:40 ...


The system is going down for reboot NOW!

Depending on when you read this, AWS may or may not have updated the version of Ubuntu from version 14.04 to 16.04. It is not required to upgrade. In fact, it is usually more convenient to wait until Amazon takes care of such things. However, should you wish to run on the latest version, run the command do-release-upgrade. Now, you are warned that upgrading via remote access is not advised and that additional access ssh scripts are being run to ports that are not likely open to the public. In particular, our security settings would prevent access to this backup access port. Since you have just created this instance, and can readily terminate from the AWS website, there is no need for such a backup access route. Hence, we simply ran the update, agreed to all the options when asked, and restarted.

If you do choose to upgrade the distribution, be sure to run the sudo update and upgrade the preceding commands one last time.

Now that our instance, or at least our packages on our instance, are updated, and we have a better sense of how to navigate in the Ubuntu file structure, we may turn our attention to installing R on our cloud server.

Installing and Using R

Our main goal so far in the last chapter and this one is to prepare a server to host R for us. We are very close to being there and have just a few more steps to perform. Our first step is to modify our package sources list so that Ubuntu knows where to find R:

cd /etc/apt/              
ubuntu@ip-10-0-0-244:/etc/apt$ ls
apt.conf.d     sources.list    trusted.gpg
preferences.d  sources.list.d  trusted.gpg.d
sudo nano sources.list

Now that the nano text editor is open, arrow down to the end of the file and add the following line of code. Then press Ctrl+O to save; you see your filename and hit Enter/Return. From there, press Ctrl+X to exit to the command line. We should note that trusty and xenial are the version 14 and 16 names for Ubuntu, so in one go we ensure that either one will work.

#Add R File server
deb http://cran.rstudio.com/bin/linux/ubuntu trusty/


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

We should mention that we are using RStudio’s kindly hosted mirror. Now, we move back into our home directory, and we also add the signature key E084DAB9 to our package utility. This allows us to confirm that any downloads we make are likely safe to download and install.

ubuntu@ip-10-0-0-244:/etc/apt$ cd /home/ubuntu            
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9


Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.jYANiNzPMT --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
gpg: requesting key E084DAB9 from hkp server keyserver.ubuntu.com
gpg: key E084DAB9: public key "Michael Rutter <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

From here, installing R is simple. In fact, it simply takes two commands. We have to update the packages list and then we need to install base R. In the setup process, you need to agree to some options once or twice.

sudo apt-get update              
sudo apt-get install r-base

Now that we have installed R on our cloud, we can run R and see what happens. We use the command R to start our program. We run one of our scripts from Chapter 1 to see what happens. The following code shows both the start screen of R as well as the familiar results of running our code:

R

R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)


R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.


  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.


Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.


x <- c("a", "b", "c")
x[1]
[1] "a"
is.vector(x)
[1] TRUE
is.vector(x[1])
[1] TRUE
is.character(x[1])
[1] TRUE

Inside R, all the commands we regularly use work as expected. We can install packages or run code. However, we would like to improve three aspects. The first is that we are running R as a user, namely, the user ubuntu. It may well be that we wish other users of our server to be able to use R without needing to have sudo or root privileges. In that case, it may be helpful to install packages not just for our user, but for the entire machine. Second, running code from files that we have created on our local machines would be convenient. Third, our connection to our server lives at the mercy of the Internet. If there is a glitch, we would lose our work. Thus, it is also convenient to get to the point where we can set our R commands to run from the command line so that even if we disconnect, our server is still calculating away.

To install packages for just a particular user, you use the install.packages("") function inside the R console as usual. However, to install a package for any user (including future users you may invite to your cloud), use the following command. What you need to do is pass a command from the command line to R. We also need to run this as root, and we need root privileges to do so, which sudo and su - provide. The -c option executes the code directly following it. Finally, we call R and set it to install the package.

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

To run code already created, we use the command R CMD BATCH. It can help to write the commands we want to use in RStudio on our local computer, use WinSCP to upload that *.R file to our instance, and then run the file as follows:

R CMD BATCH chapter21.R              
ls
chapter21.R  chapter21.Rout  MyFolder  permissionsFile

While the file chapter21.R may be downloaded from our code repository with Apress, it is simply the snippet of loop code from a preceding chapter that cubes several numbers. We can see the output in the file chapter21.Rout and we can view it by using the nano editor we used earlier in this chapter. Remember that Ctrl+X exits from that editor. We show both the command to open the file as well as an abbreviated output to demonstrate that the code ran successfully:

nano chapter21.Rout                

....
> head(xCube)
[1]   1   8  27  64 125 216
> forTime
   user  system elapsed
 11.468   1.013  12.487
....

We may now run R commands on our instance at will. This includes the parallel-processing techniques you learned in earlier chapters. Provided our code is built not to require user input, it may be readily left to run, provided you have a solid connection. We do this with the screen command. Essentially, this opens another terminal from which we can detach. This allows that terminal to keep running even if our PuTTY terminal session ends (either because we wish it to end or because network vagrancies force our hand). We can see when our process is done running as well. The command we run after our screen command with modifiers is familiar; should you wish more details about screen, the command man screen gives plenty of information.

screen -A -d -m R CMD BATCH chapter21.R                
screen -ls
There is a screen on:
        1525..ip-10-0-0-244     (03/17/2016 04:43:40 AM)        (Detached)
1 Socket in /var/run/screen/S-ubuntu.


screen -ls
No Sockets found in /var/run/screen/S-ubuntu.

As you can see from the second listing, no more processes are running. Thus it is safe to access our output file to see the results. For a process that took longer to run, rather than enter screen -ls, we might type exit and go rest. For processes that run on pricier instances, it is possible to set up AWS to e-mail an alert when processor use drops below a certain threshold.

We now have installed R on our server instance, can set up packages that are accessible to all users, and can run files without maintaining a steady network connection. If we design code on one machine that seems to take too long to run, we can upload those files to a more powerful machine and run it. However, we are still using the command line. In the next section, we install RStudio on our instance, so that we can use the familiar look and feel of RStudio while still gaining the power of a cloud instance.

Installing and Using RStudio Server

While we have shown that it is relatively straightforward to upload a file that was running too slowly on a local machine to our cloud instance, the format does leave something to be desired. RStudio (RStudio Team, 2015) is a wonderful, intuitive environment in which to code R, and we can get that same graphic interface. What is more, this can be accessible from a browser rather than from the command line. This can be quite convenient, as just about any Internet-capable device with a browser can access your instance and use R.

The risk, of course, is some security concerns. RStudio Server is protected by only a password rather than a key file. Recall from Chapter 2 how many system administrative tasks, such as file moving and deletion, may be done by R. Access to RStudio Server may enable a dedicated attacker more access to your system than desirable. We, of course, continue to keep our security group on AWS set up to allow connections only from our local IP address, although this rather curtails the promise of use of R from any device. We remind you again that data security is worth a closer look than we give here. We turn to our cloud and installation.

Since we have already installed R, we need only a little bit of work after accessing our command line again via PuTTY. To ensure proper package authentication, it helps to update, just as when we were installing system and security updates. As a side note, while installations often require a yes or no input, if asked to install packages without verification, there is likely a better way that involves verification. After each of the following apt-get commands, much text prints to your console, and you may be prompted to agree to some disk space usage.

sudo apt-get update              
...
sudo apt-get install gdebi-core
...

Once you have the ability to install the server, you need to download it from the Web. Run the following command, and expect to download a file about 51 M in size. We show the code and some of the output here; be sure to note the saved name of the file as well as a full download being complete:

wget https://download2.rstudio.org/rstudio-server-0.99.903-amd64.deb              
...
2016-10-02 15:09:44 (10.5 MB/s) - 'rstudio-server-0.99.903-amd64.deb' saved [53985492/53985492]

Now we install the server. This should require one yes agreement during the installation process:

sudo gdebi rstudio-server-0.99.903-amd64.deb              
Reading package lists... Done
Building dependency tree
Reading state information... Done
Building data structures... Done
Building data structures... Done
...
Do you want to install the software package? [y/N]:y
Selecting previously unselected package rstudio-server.
(Reading database ... 86981 files and directories currently installed.)
Preparing to unpack rstudio-server-0.99.892-amd64.deb ...
Unpacking rstudio-server (0.99.892) ...
Setting up rstudio-server (0.99.892) ...
groupadd: group 'rstudio-server' already exists
rsession: no process found
rstudio-server start/running, process 2445

To confirm that the server is running, run the verification commands as follows:

sudo rstudio-server verify-installation              
rstudio-server stop/waiting
rstudio-server start/running, process 2605Cloud Ubuntu, Windows usersRStudio Server

Now that we know our server is running, we want more confirmation that it is working. Remember in the last chapter that we set our security group to allow access to RStudio Server on port 8787. Open a web browser to your server’s web address at the needed port, namely, 54.201.117.64:8787 (or for you, YOUR_INSTANCE_IP_HERE:8787). As you can see in Figure 12-3, it does indeed visually appear that the server is working.

A393929_1_En_12_Fig3_HTML.jpg
Figure 12-3. RStudio Server

We need a username and password to gain further access. The user is also a user of your Ubuntu server and has a password. It is wise to have a password logon to the server disabled by default, which our instance does in fact have. The command we use to create a new user is adduser, and this runs the script shown for us. We need to type these commands back in our command line. It is not necessary to fill in information for your new user beyond the username and password. You can simply press Enter/Return to move to the next line. Also, note that the password field has suppressed keystrokes so that nothing populates there.

sudo adduser advancedr              
Adding user `advancedr' ...
Adding new group `advancedr' (1001) ...
Adding new user `advancedr' (1001) with group `advancedr' ...
Creating home directory `/home/advancedr' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for advancedr
Enter the new value, or press ENTER for the default
        Full Name []: Advanced R
        Room Number []: RStudio Server
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y

Going back to our browser, we use our new username and password to access RStudio Server. Enter the username and password just created, as in Figure 12-4, and you should be into RStudio on the Web.

A393929_1_En_12_Fig4_HTML.jpg
Figure 12-4. Sign into RStudio

This should feel just like the RStudio we have been using all along, as shown in Figure 12-5.

A393929_1_En_12_Fig5_HTML.jpg
Figure 12-5. RStudio on your cloud

RStudio now exists on your cloud instance. While this is helpful for a more intuitive way to work with R, the ability to more natively use and see graphical output is something we, the authors, would like to stress. Such output may be readily saved to *.pdf files and downloaded via WinSCP from the /home/advancedr folder. More generally, /home/YOUR_USERNAME accesses a particular RStudio user folder.

This completes our setup of RStudio Server. More could be done, but this is enough for starters. You now have access to a potentially powerful system, and indeed are free to have several duplicates of such systems if you wish. On AWS, it is possible to set up warnings that alert you via e-mail when your instance(s) drop below a certain CPU utilization rate. Thus, an R process may be configured to run, and instance space need not be paid for much beyond actual use time. Our final suggestion is to spend some time with the RStudio Server documentation if you intend to use it more than occasionally. There are some useful customizations, convenient features, and good-to-know caveats. We include the link in the reference section of this chapter.

Installing Microsoft R

Our cloud instance is t2.micro. As such, it has only one virtual CPU and gains no benefit from parallel-processing techniques. We have also already installed base R, so R is of course working. However, on the chance you choose to spin up more-powerful instances, we also install Microsoft R Open (MRO) and MKL (Microsoft, 2016). These files need to be installed after downloading them. We are going to give two options here. First, we install the latest version of Microsoft R Open, which is version 3.3.1 as of this writing. We also show how to install an earlier version, should you happen to have code you intend to run that requires older versions of R.

The main difference is that in the past, MRO and MKL were two separate installations. Now, starting with version 3.3.1, it is a single installation process. Type the following command in bold; the output follows:

wget "https://mran.microsoft.com/install/mro/3.3.1/microsoft-r-open-3.3.1.tar.gz"                
--2016-10-02 16:52:02--  https://mran.microsoft.com/install/mro/3.3.1/microsoft-r-open-3.3.1.tar.gz
Resolving mran.microsoft.com (mran.microsoft.com)... 166.78.134.173, 2001:4800:7813:516:be76:4eff:fe04:4c9b
Connecting to mran.microsoft.com (mran.microsoft.com)|166.78.134.173|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 268235803 (256M) [application/octet-stream]
Saving to: ‘microsoft-r-open-3.3.1.tar.gz’


microsoft-r-open-3.3.1.tar.gz 100%[================================================>] 255.81M  18.8MB/s    in 13s

2016-10-02 16:52:15 (20.1 MB/s) - ‘microsoft-r-open-3.3.1.tar.gz’ saved [268235803/268235803]  

Once the file has been downloaded, we must decompress our downloaded file. This requires privileges, so we use sudo. Using tar, we extract and ungzip our file:

sudo tar -xzf microsoft-r-open-3.3.1.tar.gz              

Next, we change our directory to our newly unzipped files by using the change directory command:

cd microsoft-r-open              
∼/microsoft-r-open$ ls
deb  install.sh  MKL_EULA.txt  MRO_EULA.txt  rpm

When installing, be sure to carefully note when to type q and when to type y. Again, the installation using the install.sh file will require sudo privileges:

∼/microsoft-r-open$ sudo ./install.sh            

Press [Enter] key to display the Microsoft R Open license. When finished reading, press q to continue:

Do you wish to install the Intel MKL libraries?
Choose [y]es|[n]o y


Press [Enter] key to display the Intel MKL license. When finished reading, press q to continue:
Do you agree to the terms of the previously displayed license?
Choose [y]es|[n]o y


Updating apt package repositories...done
Installing apt package dependencies libxt6 libsm6 libpango1.0-0 libgomp1 curl...done
Installing /home/ubuntu/microsoft-r-open/deb/microsoft-r-open-mro-3.3.deb...done
Installing /home/ubuntu/microsoft-r-open/deb/microsoft-r-open-foreachiterators-3.3.deb...done
Installing /home/ubuntu/microsoft-r-open/deb/microsoft-r-open-mkl-3.3.deb...done


Thank you for installing Microsoft R Open.
You will find logs for this installation in
/home/ubuntu/microsoft-r-open/logs

This completes the installation, and if you were on an instance that allowed for multiple threads, you would have access. This bundle of MRO and MKL is new, and thus, for completeness for backward compatibility, we include instructions for the older file type as well. To install older versions such as 3.2.4, in the command line, use the wget command:

wget "https://mran.microsoft.com/install/mro/3.2.4/MRO-3.2.4-Ubuntu-14.4.x86_64.deb"              

Then type the following:

wget "https://mran.microsoft.com/install/mro/3.2.4/RevoMath-3.2.4.tar.gz"              

After those have downloaded, use the ls command to see that it worked:

ls              
chapter21.R                       permissionsFile  RevoMath-3.2.4.tar.gz              slider_time
MRO-3.2.4-Ubuntu-14.4.x86_64.deb  PieChart_Time    rstudio-server-0.99.892-amd64.deb  Upload_hist
MyFolder                          R                shiny-server-1.4.2.786-amd64.deb

Next, enter the following code into the command line:

sudo dpkg -i MRO-3.2.4-Ubuntu-14.4.x86_64.deb              

Now that Microsoft R Open is installed, we add the parallel-processing support:

sudo tar -xzf RevoMath-3.2.4.tar.gz              
cd RevoMath
ubuntu@ip-10-0-0-244:∼/RevoMath$ ls
mkl  mklLicense.txt  RevoMath.sh  RevoUtilsMath.tar.gz
ubuntu@ip-10-0-0-244:∼/RevoMath$ sudo ./RevoMath.sh

After that last line, you want to select option 1 by typing 1 and then pressing Enter/Return. Hit Enter/Return a few times to get through the license agreement text (depending on screen size), but not too many times or you negate the agreement. When prompted, type y and hit Enter/Return. That’s it! Should you have more than one core, the cloud now works as MRO has been working for us on Windows.

Installing Java

Next, we install Java . It is quite easy; just run the following three lines of code, one at a time, in the command line. Agree to things as needed.

sudo apt-get update              
sudo apt-get install default-jre
sudo apt-get install default-jdk

Installing Shiny on Your Cloud

Bringing statistics to information consumers is the main use for Shiny. Because we are in installation mode, we’ll go ahead and install the needed resources on our cloud instance to host a Shiny application.

To install Shiny, we need to run the following code. An agreement is required to confirm an installation, and we suppress the system’s output to the command line. Run each line by itself.

This line installs the shiny package (Chang, Cheng, Allaire, Xie, and McPherson, 2016) into R. In addition, we also install xlsx (Dragulescu, 2014) and shinydashboard (Chang, 2015). You notice that between the inner parentheses, there are commands that make lots of sense to R users. However, in this case, we are running R from the command line, specifically, so we can execute the process with administrative privileges and thus have access to these libraries from any Ubuntu user account rather than just the main user account. When a Shiny server hosts applications, it hosts them by using the username shiny. Hence, the following three lines of code install these packages for all users:

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

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

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

From here, now that R itself can use Shiny, we install the server so that our cloud instance can serve Shiny apps to the Internet. We have to download a file with the wget command and then install that file. We do that with the following lines of code, and there are some installation disclaimers.

wget https://download3.rstudio.org/ubuntu-12.04/x86_64/shiny-server-1.4.6.809-amd64.deb                

sudo gdebi shiny-server-1.4.6.809-amd64.deb

Final Thoughts

You now have access to a cloud instance that has RStudio Server (which can be quite convenient). In particular, you have the ability to upload files to and from a local machine in a way that does not require superuser local privileges. If you opened up permission access by unrestricting more IP addresses, this is a way to use R from a smartphone. Also, we installed several packages and applications on our Ubuntu server. In the next chapters, we use those features to make some absorbing analytics happen. More important, because they are served on the cloud, these data and results are accessible to anyone. Thus, sharing results has never been easier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.64.172