Chapter 4. Taking Control of Reactivity, Inputs, and Outputs

So far in this book, we've mastered the basics of Shiny by building our own Google Analytics application as well as looked at how to style and extend Shiny applications using HTML, CSS, and JavaScript. In this chapter, we are going to extend our toolkit by learning about advanced Shiny functions. These allow you to take control of the fine details of your application, including the interface, reactivity, data, and graphics.

In order to do this, we're going to go back to the Google Analytics application and totally upgrade it, making it much smoother, more intuitive, and well-featured. The finished code and data for this advanced Google Analytics application can be found at github.com/ChrisBeeley/GoogleAnalytics2ndEdition.

In this chapter, we will cover the following topics:

  • Learning how to show and hide parts of the interface
  • Changing the interface reactively
  • Finely controlling reactivity, so functions and outputs run at the appropriate time
  • Using URLs and reactive Shiny functions to populate and alter the selections within an interface
  • Uploading and downloading data to and from a Shiny application
  • Producing beautiful tables with the DataTables jQuery library
  • Using custom graphics and animations in Shiny
  • Showing progress bars to users in long running functions
  • Debugging Shiny code

What's new in our application?

We're going to add a lot of new functionality to the application, and it won't be possible to explain every piece of code before we encounter it. Several of the new functions depend on at least one other function, which means that you will see some of the functions for the first time while a different function is being introduced.

It's important, therefore, that you concentrate on whichever function is being explained and wait until later in the chapter to understand the whole piece of code. New functions that are explained later in the chapter will be noted as we progress. In order to help you understand what the code does as you go along, it is worth quickly reviewing the actual functionality of the application now. You can find a link to a hosted version of the application within the GitHub page referenced in the introduction to this chapter. It is definitely worth visiting this page to see the application in action yourself.

In terms of the functionality, which has been added to the application, it is now possible to select not only the network domain from which browser hits originate but also the country of origin. The draw map function now features a button in the UI, which prevents the application from updating the map each time new data is selected, the map is redrawn only when the button is pushed. This is to prevent minor updates to the data from wasting processor time before the user has finished making their final data selection.

A Download report button has been added, which sends some of the output as a static file to a new web page for the user to print or download. An animated graph of trend has been added; this will be explained more fully in the relevant section and, finally, a table of data has been added, which summarizes mean values of each of the selectable data summaries across the different countries of origin.

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

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