ui.R

We're going to use the Gapminder application we've been looking at throughout the book, but add a little JavaScript magic. We're going to add a button that, when clicked, writes the currently selected years on the summary text tab. Let's take a look at what we're adding to the ui.R file, over in the sidebarPanel() function:

tags$input(type = "button",            id = "append",            value = "Add current input values",           onClick = "buttonClick()"),      includeHTML("appendText.js") 

As you can see, we use the tags$xxx() function that we saw in Chapter 3, Integrating Shiny with HTML, in order to generate a button that will run a JavaScript action when it's clicked. It generates the following HTML:

<input type="button" id="append" value="Add current input values" ...

Get Web Application Development with R Using Shiny - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.