O'Reilly logo

Learning Shiny by Hernán G. Resnizky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required