Book Image

Web Application Development with R Using Shiny Second Edition - Second Edition

By : Chris Beeley
Book Image

Web Application Development with R Using Shiny Second Edition - Second Edition

By: Chris Beeley

Overview of this book

R is a highly flexible and powerful tool for analyzing and visualizing data. Most of the applications built using various libraries with R are desktop-based. But what if you want to go on the web? Here comes Shiny to your rescue! Shiny allows you to create interactive web applications using the excellent analytical and graphical capabilities of R. This book will guide you through basic data management and analysis with R through your first Shiny application, and then show you how to integrate Shiny applications with your own web pages. Finally, you will learn how to finely control the inputs and outputs of your application, along with using other packages to build state-of-the-art applications, including dashboards.
Table of Contents (14 chapters)
Web Application Development with R Using Shiny Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Harness the graphical and statistical power of R, and rapidly develop interactive and engaging user interfaces using the superb Shiny package, which makes programming for user interaction simple. R is a highly flexible and powerful tool used for analyzing and visualizing data. Shiny is the perfect companion to R, making it quick and simple to share analysis and graphics from R that users can interact with and query over the Web. Let Shiny do the hard work and spend your time generating content and styling, not writing code to handle user inputs. This book is full of practical examples and shows you how to write cutting-edge interactive content for the Web, right from a minimal example all the way to fully styled and extensible applications.

This book includes an introduction to Shiny and R and takes you all the way to advanced functions in Shiny as well as using Shiny in conjunction with HTML, CSS, and JavaScript to produce attractive and highly interactive applications quickly and easily. It also includes a detailed look at other packages available for R, which can be used in conjunction with Shiny to produce dashboards, maps, advanced D3 graphics, among many things.

What this book covers

Chapter 1, Getting Started with R and Shiny!, runs through the basics of statistical graphics, data input, and analysis with R. We also discuss data structures and programming basics in R in order to give you a thorough grounding in R before we look at Shiny.

Chapter 2, Building Your First Application, helps you build your first Shiny application. We begin with simply adding interactive content to a document written in markdown, and then delve deeper into Shiny, building a very primitive minimal example, and finally, looking at more complex applications and the inputs and outputs necessary to build them.

Chapter 3, Building Your Own Web Pages with Shiny, covers how Shiny works with existing web content in HTML, CSS, and JavaScript. We discuss the Shiny helper functions that allow you to add a custom HTML to a standard Shiny application and how to build a minimal example of a Shiny application in your own raw HTML with Shiny running in the background. Finally, we also discuss using JavaScript/ jQuery with Shiny with examples given to add bells and whistles to an existing application as well as providing powerful interactive tools to communicate between the web page and Shiny using JavaScript.

Chapter 4, Taking Control of Reactivity, Inputs, and Outputs, covers advanced functions in Shiny in detail, in particular, changing the UI based on user input or the state of the application, finely controlling reactivity in your application, and advanced methods used for reading user input as well as specialized graphics and data tables. We also cover debugging, which can pose challenges in Shiny applications.

Chapter 5, Advanced Applications I – Dashboards, contains detailed information of the layout in Shiny applications. We discuss simple ways to use layout functions described earlier in the book, and how to use the Bootstrap style on which Shiny is based. Finally, we also cover how a full dashboard is produced with several pages, specialized input and output widgets, and other advanced features accessible when using Shiny dashboards.

Chapter 6, Advanced Applications II – Using JavaScript Libraries in Shiny Applications, reviews some of the many JavaScript libraries, which can easily be integrated into Shiny, and how to use them in your own Shiny applications. We also cover how to draw graphics, which describe trends and predictions, heatmaps and highly interactive charts using D3, and 3D plots, along with an advice on how best to ensure that they work within Shiny.

Chapter 7, Sharing Your Creations, discusses the many different ways to share Shiny applications with your end users. There are many ways of doing this and they are described in detail, including the use of the Gist and GitHub website, locally using a simple ZIP file, hosting them yourself on your own server, or making use of RStudio's hosting services. We also cover reading and writing data using Shiny in a server (as opposed to a local) environment.

What you need for this book

This book can be used with the Windows, Mac, or Linux operating systems. It requires the installation of R as well as several user-contributed packages within R. R and its associated packages are all available for free. The RStudio IDE is recommended because it simplifies some of the tasks covered in this book but are not essential. Again, this software is available free of charge.

Who this book is for

This book is for anybody who wants to produce interactive data summaries over the Web, whether you want to share them with a few colleagues or the whole world. No previous experience with R, Shiny, HTML, or CSS is required to begin using this book, although you should possess some previous experience with programming in a different language.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can see the separation of input code sliderInput() and output code renderPlot()."

A block of code is set as follows:

conditionalPanel(
  condition = "input.theTabs == 'trend'",
  checkboxInput("smooth", label = "Add smoother?", # add smoother
    value = FALSE)
)

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

tabPanel("Trend", plotOutput("trend"),
  value = "trend")

Any command-line input or output is written as follows:

> runGitHub("basicGoogleAnalytics2ndEdition", "ChrisBeeley")

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Navigate to File | New | R Markdown | New document and enter the code."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.