Book Image

Learning Shiny

By : Hernan Resnizky
Book Image

Learning Shiny

By: Hernan Resnizky

Overview of this book

Table of Contents (19 chapters)
Learning Shiny
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Introducing R, RStudio, and Shiny
Index

Including a plot in a Shiny application


When we include graphics inside a Shiny application, all the elements that are seen can be handled within a reactive context. Taking the same previous example, in the following code, you will see how to use reactivity inside graphical parameters.

In this case, a fixed color is assigned to every species, so the color assignment can be done outside the reactive context. In this case, we will be doing it inside global.R because the inputs in UI.R are going to be defined as the levels of iris$Species, as it was explained in Chapter 4, Shiny Structure – Reactivity Concepts:

global.R# Load Data
data(iris)

#Assign color by Species
iris$color <- sapply(iris$Species, function(x) switch(as.character(x),
setosa = "red",
versicolor = "green",
virginica = "blue"))

UI.R has two types of inputs; firstly, the species (within checkboxGroupInput) and secondly, the variables in the horizontal and vertical axes respectively. For the purpose of simplicity, the first...