6 min read

KPI dashboard in R with animated icons

So Key Performance Indicators (KPIs) are all the rage in the dashboarding community… well So Key Performance Indicators (KPIs) are all the rage in the dashboarding community… well really. The premise is simple… check a list of measurements against targets and show how they compare using some kind of visualization. I haven’t yet seen, however, a version that can utilize animated icons to display indicators that REALLY need attention. So here you go, a tutorial on how to make your very own animated icon KPI, using the googleVis library.

Suppose we have a dataset that looks like this (make sure to set your working directory):

`library(googleVis)

Set wd

setwd(“your folder”)
df <- data.frame(thing=paste(“Item”,1:15),
measure=round(runif(15,max=10),2),
target=round(runif(15,max=10),2))

unimpresive dashboard

plot(gvisTable(df))`

data

A normal KPI would then compare the measure to the target and apply some rationale. Suppose in our case that green indicates that for that indicator you are within 80% of your target. Yellow means up to 50% of target, and red is below that.

Now, we need some icons. We can download them, or make them ourselves (protip: MS Powerpoint has some interesting possibilities with their glow/highlight/dropshadow options so this might be a good place to start if you’re not a graphic designer). Now that we have icons, we can split up the dataset into good, bad and medium categories and assign icons to each:

 

``So Key Performance Indicators (KPIs) are all the rage in the dashboarding community… well So Key Performance Indicators (KPIs) are all the rage in the dashboarding community… well really. The premise is simple… check a list of measurements against targets and show how they compare using some kind of visualization. I haven’t yet seen, however, a version that can utilize animated icons to display indicators that REALLY need attention. So here you go, a tutorial on how to make your very own animated icon KPI, using the googleVis library.

Suppose we have a dataset that looks like this (make sure to set your working directory):

`library(googleVis)

Set wd

setwd(“your folder”)
df <- data.frame(thing=paste(“Item”,1:15),
measure=round(runif(15,max=10),2),
target=round(runif(15,max=10),2))

unimpresive dashboard

plot(gvisTable(df))`

data

A normal KPI would then compare the measure to the target and apply some rationale. Suppose in our case that green indicates that for that indicator you are within 80% of your target. Yellow means up to 50% of target, and red is below that.

Now, we need some icons. We can download them, or make them ourselves (protip: MS Powerpoint has some interesting possibilities with their glow/highlight/dropshadow options so this might be a good place to start if you’re not a graphic designer). Now that we have icons, we can split up the dataset into good, bad and medium categories and assign icons to each:

 

``

ohnoes

Oh no! Why won’t it work? Relax, it’s because we are in the localhost. See how the address is http://127.0.0.1/… ? This isn’t a real webpage, it’s launching from your computer. We need to port out the right elements into a handy-dandy webpage (the code is very ugly, but SUPER flexible… you can pass css elements, titles, javascript… hell you can even create a fully functional webpage like this! I love this method, don’t bash it!):


Suppose we have a dataset that looks like this (make sure to set your working directory):

`library(googleVis)<br />
## Set wd<br />
setwd("your folder")<br />
df <- data.frame(thing=paste("Item",1:15),<br />
measure=round(runif(15,max=10),2),<br />
target=round(runif(15,max=10),2))<br />
## unimpresive dashboard<br />
plot(gvisTable(df))`

<a href="https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png" rel="attachment wp-att-555"><img class="alignnone size-medium wp-image-555" src="https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png?resize=165%2C300" alt="data" width="165" height="300" srcset="https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png?resize=165%2C300 165w, https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png?w=303 303w" sizes="(max-width: 165px) 100vw, 165px" data-recalc-dims="1" /></a>

A normal KPI would then compare the measure to the target and apply some rationale. Suppose in our case that green indicates that for that indicator you are within 80% of your target. Yellow means up to 50% of target, and red is below that.

Now, we need some icons. We can download them, or make them ourselves (protip: MS Powerpoint has some interesting possibilities with their glow/highlight/dropshadow options so this might be a good place to start if you&#8217;re not a graphic designer). Now that we have icons, we can split up the dataset into good, bad and medium categories and assign icons to each:

&nbsp;

``So Key Performance Indicators (KPIs) are all the rage in the dashboarding community&#8230; well [So Key Performance Indicators (KPIs) are all the rage in the dashboarding community&#8230; well][1] really. The premise is simple&#8230; check a list of measurements against targets and show how they compare using some kind of visualization. I haven&#8217;t yet seen, however, a version that can utilize animated icons to display indicators that REALLY need attention. So here you go, a tutorial on how to make your very own animated icon KPI, using the googleVis library.

Suppose we have a dataset that looks like this (make sure to set your working directory):

`library(googleVis)<br />
## Set wd<br />
setwd("your folder")<br />
df <- data.frame(thing=paste("Item",1:15),<br />
measure=round(runif(15,max=10),2),<br />
target=round(runif(15,max=10),2))<br />
## unimpresive dashboard<br />
plot(gvisTable(df))`

<a href="https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png" rel="attachment wp-att-555"><img class="alignnone size-medium wp-image-555" src="https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png?resize=165%2C300" alt="data" width="165" height="300" srcset="https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png?resize=165%2C300 165w, https://i1.wp.com/amitkohli.com/wp-content/uploads/2016/02/data.png?w=303 303w" sizes="(max-width: 165px) 100vw, 165px" data-recalc-dims="1" /></a>

A normal KPI would then compare the measure to the target and apply some rationale. Suppose in our case that green indicates that for that indicator you are within 80% of your target. Yellow means up to 50% of target, and red is below that.

Now, we need some icons. We can download them, or make them ourselves (protip: MS Powerpoint has some interesting possibilities with their glow/highlight/dropshadow options so this might be a good place to start if you&#8217;re not a graphic designer). Now that we have icons, we can split up the dataset into good, bad and medium categories and assign icons to each:

&nbsp;

`` 

<a href="https://i2.wp.com/amitkohli.com/wp-content/uploads/2016/02/ohnoes.png" rel="attachment wp-att-559"><img class="alignnone size-medium wp-image-559" src="https://i2.wp.com/amitkohli.com/wp-content/uploads/2016/02/ohnoes.png?resize=151%2C300" alt="ohnoes" width="151" height="300" srcset="https://i2.wp.com/amitkohli.com/wp-content/uploads/2016/02/ohnoes.png?resize=151%2C300 151w, https://i2.wp.com/amitkohli.com/wp-content/uploads/2016/02/ohnoes.png?w=226 226w" sizes="(max-width: 151px) 100vw, 151px" data-recalc-dims="1" /></a>

Oh no! Why won&#8217;t it work? Relax, it&#8217;s because we are in the localhost. See how the address is http://127.0.0.1/&#8230; ? This isn&#8217;t a real webpage, it&#8217;s launching from your computer. We need to port out the right elements into a handy-dandy webpage <span style="color: #999999;">(the code is very ugly, but SUPER flexible&#8230; you can pass css elements, titles, javascript&#8230; hell you can even create a fully functional webpage like this! I love this method, don&#8217;t bash it!)</span>:

and now check it out:

better

 

Not bad… this is what most KPI indicator lights look like… But what if we REALLY want to call the attention to some items, say where the measure is less than 20% of the target, let’s bring out the big guns and assign a red flashing light to the terriblest:

`Threshold3 <- 0.2

lowlowlowlowlow trigger

df$graphic[df$measure/df$target < Threshold3] <-

##— Make html again —-
ObsRep <- gvisTable(df)

plot(ObsRep)

cat(paste("",

Best Dashborde!!!1!

",sep=”"),
ObsRep$html$header,
ObsRep$html$chart,
“”,
file=“AnimatedKPIdashboard.html”)
browseURL(“AnimatedKPIdashboard.html”)`

And voilà! Here’s our KPI with a flashing red light for the real underperformers:

(The link also here: »AnimatedKPIdashboard«)

And from here the sky is the limit! Enjoy re-discovering animated gifs! There’s a few gems out there.

As always, full code is in my github account.

 

(Editing by Laure Belotti)