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", ...