Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Learning Shiny
Learning Shiny

Learning Shiny: Make the most of R's dynamic capabilities and implement web applications with Shiny

eBook
£7.99 £26.99
Paperback
£32.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Shiny

Chapter 1. Introducing R, RStudio, and Shiny

In this chapter, the main objective will be to learn how to install all the needed components to build an application in R with Shiny. Additionally, some general ideas about what R is will be covered in order to be able to dive deeper into programming using R.

The following topics will be covered in this chapter:

  • A brief introduction to R, RStudio, and Shiny
  • Installation of R and Shiny
  • General tips and tricks

About R

As stated on the R-project main website:

"R is a language and environment for statistical computing and graphics."

R is a successor of S and is a GNU project. This means, briefly, that anyone can have access to its source codes and can modify or adapt it to their needs. Nowadays, it is gaining territory over classic commercial software, and it is, along with Python, the most used language for statistics and data science.

Regarding R's main characteristics, the following can be considered:

  • Object oriented: R is a language that is composed mainly of objects and functions. Chapter 2, First Steps towards Programming in R, and Chapter 3, An Introduction to Data Processing in R, will cover object and function handling in R.
  • Can be easily contributed to: Similar to GNU projects, R is constantly being enriched by users' contributions either by making their codes accessible via "packages" or libraries, or by editing/improving its source code. There are actually almost 7000 packages in the common R repository, Comprehensive R Archive Network (CRAN). Additionally, there are other R repositories of public access, such as the bioconductor project which contains packages for bioinformatics.
  • Runtime execution: Unlike C or Java, R does not need compilation. This means that you can, for instance, write 2 + 2 in the console and it will return the value.
  • Extensibility: The R functionalities can be extended through the installation of packages and libraries. Standard proven libraries can be found in CRAN repositories and are accessible directly from R by typing install.packages().

Installing R

R can be installed in every operating system. It is highly recommended to download the program directly from http://cran.rstudio.com/ when working on Windows or Mac OS. On Ubuntu, R can be easily installed from the terminal as follows:

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

The installation of r-base-dev is highly recommended as it is a package that enables users to compile the R packages from source, that is, maintain the packages or install additional R packages directly from the R console using the install.packages() command.

To install R on other UNIX-based operating systems, visit the following links:

A quick guide to R

When working on Windows, R can be launched via its application. After the installation, it is available as any other program on Windows. When opening the program, a window like this will appear:

A quick guide to R

When working on Linux, you can access the R console directly by typing R on the command line:

A quick guide to R

In both the cases, R executes in runtime. This means that you can type in code, press Enter, and the result will be given immediately as follows:

> 2+2
[1] 4

The R application in any operating system does not provide an easy environment to develop code. For this reason, it is highly recommended (not only to write web applications in R with Shiny, but for any task you want to perform in R) to use an Integrated Development Environment (IDE).

The topics related to the R language are covered mainly in Chapter 2, First Steps towards Programming in R, and Chapter 3, An Introduction to Data Processing in R.

About RStudio

As with other programming languages, there is a huge variety of IDEs available for R. IDEs are applications that make code development easier and clearer for the programmer. RStudio is one of the most important ones for R, and it is especially recommended to write web applications in R with Shiny because this contains features specially designed for this purpose. Additionally, RStudio provides facilities to write C++, Latex, or HTML documents and also integrates them to the R code.

RStudio also provides version control, project management, and debugging features among many others.

Installing RStudio

RStudio for desktop computers can be downloaded from its official website at http://www.rstudio.com/products/rstudio/download/ where you can get versions of the software for Windows, MAC OS X, Ubuntu, Debian, and Fedora.

A quick guide to RStudio

Before installing and running RStudio, it is important to have R installed. As it is an IDE and not the programming language, it will not work at all. The following screenshot shows RStudio's starting view:

A quick guide to RStudio

At the first glance, the following four main windows are available:

  • Text editor: This provides facilities to write R scripts such as highlighting and a code completer (when hitting Tab, you can see the available options to complete the code written). It is also possible to include R code in an HTML, Latex, or C++ piece of code.
  • Environment and history: They are defined as follows:
    • In the Environment section, you can see the active objects in each environment. By clicking on Global Environment (which is the environment shown by default), you can change the environment and see the active objects. You can find more information about environments in a chapter dedicated to this topic in the book Advanced R, by Hadley Wickham. It is available at http://adv-r.had.co.nz/Environments.html.
    • In the History tab, the pieces of codes executed are stored line by line. You can select one or more lines and send them either to the editor or to the console. In addition, you can look up for a certain specific piece of code by typing it in the textbox in the top right part of this window.
  • Console: This is an exact equivalent of R console, as described in Quick guide of R.
  • Tabs: The different tabs are defined as follows:
    • Files: This consists of a file browser with several additional features (renaming, deleting, and copying). Clicking on a file will open it in editor or the Environment tab depending on the type of the file. If it is a .rda or .RData file, it will open in both. If it is a text file, it will open in one of them.
    • Plots: Whenever a plot is executed, it will be displayed in that tab.
    • Packages: This shows a list of available and active packages. When the package is active, it will appear as clicked. Packages can also be installed interactively by clicking on Install Packages.
    • Help: This is a window to seek and read active packages' documentation.
    • Viewer: This enables us to see the HTML-generated content within RStudio.

Along with numerous features, RStudio also provides keyboard shortcuts. A few of them are listed as follows:

Description

Windows/Linux

OSX

Complete the code.

Tab

Tab

Run the selected piece of code. If no piece of code is selected, the active line is run.

Ctrl + Enter

⌘ + Enter

Comment the selected block of code.

Ctrl + Shift + C

⌘ + /

Create a section of code, which can be expanded or compressed by clicking on the arrow to the left. Additionally, it can be accessed by clicking on it in the bottom left menu.

#####

#####

Find and replace.

Ctrl + F

⌘ + F

The following screenshots show how a block of code can be collapsed by clicking on the arrow and how it can be accessed quickly by clicking on its name in the bottom-left part of the window:

A quick guide to RStudio

Clicking on the circled arrow will collapse the Section 1 block, as follows:

A quick guide to RStudio

The full list of shortcuts can be found at https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts.

Note

For further information about other RStudio features, the full documentation is available at https://support.rstudio.com/hc/en-us/categories/200035113-Documentation.

About Shiny

Shiny is a package created by RStudio, which enables to easily interface R with a web browser. As stated in its official documentation, Shiny is a web application framework for R that makes it incredibly easy to build interactive web applications with R.

One of its main advantages is that there is no need to combine R code with HTML/JavaScript code as the framework already contains prebuilt features that cover the most commonly used functionalities in a web interactive application. There is a wide range of software that has web application functionalities, especially oriented to interactive data visualization. What are the advantages of using R/Shiny then, you ask? They are as follows:

  • It is free not only in terms of money but (as with all GNU projects) in terms of freedom. As stated in the GNU main page: To understand the concept, you should think of "free" as in "free speech", not as in "free beer". Free software is a matter of the users' freedom to run, copy, distribute, study, change, and improve the software.
  • All the possibilities of a powerful language such as R is available. Thanks to its contributive essence, you can develop a web application that can display any R-generated output. This means that you can, for instance, run complex statistical models and return the output in a friendly way in the browser, obtain and integrate data from the various sources and formats (for instance, SQL, XML, JSON, and so on) the way you need, and subset, process, and dynamically aggregate the data the way you want. These options are not available (or are much more difficult to accomplish) under most of the commercial BI tools.

Installing and loading Shiny

As with any other package available in the CRAN repositories, the easiest way to install Shiny is by executing install.packages("shiny").

The following output should appear on the console:

Installing and loading Shiny

Due to R's extensibility, many of its packages use elements (mostly functions) from other packages. For this reason, these packages are loaded or installed when the package that is dependent on them is loaded or installed. This is called dependency. Shiny (on its 0.10.2.1 version) depends on Rcpp, httpuv, mime, htmltools, and R6.

An R session is started only with the minimal packages loaded. So if functions from other packages are used, they need to be loaded before using them. The corresponding command for this is as follows:

library(shiny)

When installing a package, the package name must be quoted but when loading the package, it must be unquoted.

Summary

After these instructions, the reader should be able to install all the fundamental elements to create a web application with Shiny. Additionally, he or she should have acquired at least a general idea of what R and the R project is.

The next chapter will focus on the first steps of programming in R and the key elements of this language.

Left arrow icon Right arrow icon

Description

Make the most of R’s dynamic capabilities and implement web applications with Shiny About This Book Present interactive data visualizations in R within the Shiny framework Construct web dashboards in a simple, intuitive, but fully flexible environment Apply your skills to create a real-world web application with this step-by-step guide Who This Book Is For If you are a data scientist who needs a platform to show your results to a broader audience in an attractive and visual way, or a web developer with no prior experience in R or Shiny, this is the book for you. What You Will Learn Comprehend many useful functions, such as lapply and apply, to process data in R Write and structure different files to create a basic dashboard Develop graphics in R using popular graphical libraries such as ggplot2 and GoogleVis Mount a dashboard on a Linux Server Integrate Shiny with non-R-native visualization, such as D3.js Design and build a web application In Detail R is nowadays one of the most used tools in data science. However, along with Shiny, it is also gaining territory in the web application world, due to its simplicity and flexibility. Shiny is a framework that enables the creation of interactive visualizations written entirely in R and can be displayed in almost any ordinary web browser. It is a package from RStudio, which is an IDE for R. From the fundamentals of R to the administration of multi-concurrent, fully customized web applications, this book explains how to achieve your desired web application in an easy and gradual way. You will start by learning about the fundamentals of R, and will move on to looking at simple and practical examples. These examples will enable you to grasp many useful tools that will assist you in solving the usual problems that can be faced when developing data visualizations. You will then walk through the integration of Shiny with R in general and view the different visualization possibilities out there. Finally, you will put your skills to the test and create your first web application! Style and approach This is a comprehensive, step-by-step guide that will allow you to learn and make full use of R and Shiny’s capabilities in a gradual way, together with clear, applied examples.

What you will learn

  • Comprehend many useful functions, such as lapply and apply, to process data in R Write and structure different files to create a basic dashboard Develop graphics in R using popular graphical libraries such as ggplot2 and GoogleVis Mount a dashboard on a Linux Server Integrate Shiny with non-R-native visualization, such as D3.js Design and build a web application

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 16, 2015
Length: 246 pages
Edition : 1st
Language : English
ISBN-13 : 9781785281990
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 16, 2015
Length: 246 pages
Edition : 1st
Language : English
ISBN-13 : 9781785281990
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 107.97
Mastering RStudio: Develop, Communicate, and Collaborate with R
£41.99
Learning Shiny
£32.99
Web Application Development with R Using Shiny Second Edition
£32.99
Total £ 107.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. Introducing R, RStudio, and Shiny Chevron down icon Chevron up icon
2. First Steps towards Programming in R Chevron down icon Chevron up icon
3. An Introduction to Data Processing in R Chevron down icon Chevron up icon
4. Shiny Structure – Reactivity Concepts Chevron down icon Chevron up icon
5. Shiny in Depth – A Deep Dive into Shiny's World Chevron down icon Chevron up icon
6. Using R's Visualization Alternatives in Shiny Chevron down icon Chevron up icon
7. Advanced Functions in Shiny Chevron down icon Chevron up icon
8. Shiny and HTML/JavaScript Chevron down icon Chevron up icon
9. Interactive Graphics in Shiny Chevron down icon Chevron up icon
10. Sharing Applications Chevron down icon Chevron up icon
11. From White Paper to a Full Application Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9
(7 Ratings)
5 star 28.6%
4 star 0%
3 star 28.6%
2 star 14.3%
1 star 28.6%
Filter icon Filter
Top Reviews

Filter reviews by




M. Rumore Jan 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I disagree with the other reviewers. This book is an introduction to Shiny and it covers the case where the reader may also be new to R.It provides an excellent description of the Shiny archictecture, the connection between the UI processing and the data-processing backend. The chapters slowly progress through the various Shiny capabilites with straightforward examples which are easy to understand and demonstrate the interactions between user-input, data processing, UI updates, etc. It also covers (briefly) how to include HTML, CSS, javascript into Shiny applications.The final chapter develops an application where all the parts are linked and demonstrated.If you need more details, then you do have to look elsewhere.
Amazon Verified review Amazon
Oscar Jun 11, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excelente libro
Amazon Verified review Amazon
Ray O Light Nov 30, 2015
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This is value for money given the technical content of the book.What I liked about the book is that it goes straight to giving the technical knowledge and understanding of Shiny.Where I would think it could be better is to bring the last chapter forward and start off with an overarching view of using Shiny and its Conceptual design (this would help the reader to associate better web design and using Shiny). Also suggest removing the introduction to R portion, which is too brief and not necessary since it is very likely people who wish to learn about Shiny already know R. (started reading straight from chapter 4).Overall, this book is geared more towards the technical aspect and helps to stir interest in picking up Shiny development.
Amazon Verified review Amazon
Amazon Customer Nov 19, 2015
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
There are very rare books written on shiny. It is an introductory book to get you started with Shiny. The book covers very basic examples so do n't expect to have expert skills after reading this book. Chapter 11 From White Paper to a Full Application did nice job in giving an overview of end to end development process.
Amazon Verified review Amazon
MR MW GREGORY Oct 10, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Online tutorials provided by R Studio are superior. Provides little additional value for the cost. Probably good if you are new to R and Shiny, not good for advanced users.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.