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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Web Application Development with R Using Shiny Second Edition

You're reading from   Web Application Development with R Using Shiny Second Edition Integrate the power of R with the simplicity of Shiny to deliver cutting-edge analytics over the Web

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher Packt
ISBN-13 9781782174349
Length 194 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Chris Beeley Chris Beeley
Author Profile Icon Chris Beeley
Chris Beeley
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Getting Started with R and Shiny! FREE CHAPTER 2. Building Your First Application 3. Building Your Own Web Pages with Shiny 4. Taking Control of Reactivity, Inputs, and Outputs 5. Advanced Applications I – Dashboards 6. Advanced Applications II – Using JavaScript Libraries in Shiny Applications 7. Sharing Your Creations Index

Installing Shiny and running the examples

Shiny can be installed using standard package management functions as described previously (using the GUI or running install.packages("shiny") at the console).

Let's run some of the examples:

> library(shiny)
> runExample("01_hello")

Your web browser should launch and display the following screenshot (note that I clicked on the show below button on the app to better fit the graphic on the page):

Installing Shiny and running the examples

The graph shows the frequency of a set of random numbers drawn from a statistical distribution known as the normal distribution, and the slider allows users to select the size of the draw, from 0 to 1000. You will note that when you move the slider, the graph updates automatically. This is a fundamental feature of Shiny, which makes use of a reactive programming paradigm.

This is a type of programming that uses reactive expressions, which keep track of the values on which they are based that can change (known as reactive values) and update themselves whenever any of their reactive values change. So, in this example, the function that generates the random data and draws the graph is a reactive expression, and the number of random draws that it makes is a reactive value on which the expression depends. So, whenever the number of draws changes, the function re-executes.

Note

You can find more information about this example as well as a comprehensive tutorial for Shiny at shiny.rstudio.com/tutorial/.

Also, note the layout and style of the web page. Shiny is based by default on the bootstrap theme (getbootstrap.com/). However, you are not limited by the styling at all and can build the whole UI using a mix of HTML, CSS, and Shiny code.

Let's look at an interface made with bare-bones HTML and Shiny. Note that in this and all subsequent examples, we're going to assume that you run library(shiny) at the beginning of each session. You don't have to run it before each example except at the beginning of each R session. So, if you have closed R and come back, then run it at the console. If you can't remember, run it again to be sure, as follows:

> runExample("08_html")

And here it is, in all its customizable glory:

Installing Shiny and running the examples

Now there are a few different statistical distributions to pick from and a different method of selecting the number of observations. By now, you should be looking at the web page and imagining all the possibilities there are to produce your own interactive data summaries and styling them just how you want, quickly and simply. By the end of the next chapter, you'll have made your own application with the default UI, and by the end of the book, you'll have complete control over the styling and be pondering where else you can go.

There are lots of other examples included with the Shiny library; just type runExample() at the console to be provided with a list.

To see some really powerful and well-featured Shiny applications, take a look at the showcase at shiny.rstudio.com/gallery/.

You have been reading a chapter from
Web Application Development with R Using Shiny Second Edition - Second Edition
Published in: Jan 2016
Publisher: Packt
ISBN-13: 9781782174349
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image