Animation

Animation is surprisingly easy. The sliderInput() function, which provides an HTML widget that allows us to select a number along a line, has an optional animation function that will increment a variable by a set amount every time a specified unit of time elapses. This allows you to very easily produce a graphic that is animated.

In the following example, we are going to look at the monthly graph and plot a linear trend line through the first 20% of the data (0-20% of the data). Then, we are going to increment the percentage value that selects the portion of the data by 5% and plot a linear through that portion of data (5-25% of the data). Then, increment by 10-30% and plot another line, and so on.

The slider input is set up as ...

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.