assembled with blockbuilder.org
I wanted to iterate through a couple more of these examples before a CRAN submission of the sparkline
htmlwidgets
package. In this example, I tried to approach sparklines + formattable + dplyr in R slightly differently than in some of the other examples.
library(sparkline)
library(htmltools)
library(htmlwidgets)
library(dplyr)
mtcars %>%
group_by(cyl) %>%
summarise(
hp = as.character(
as.tags(
sparkline(hp, type="box", chartRangeMin=0, chartRangeMax=400)
)
),
mpg = as.character(
as.tags(
sparkline(mpg, type="box", chartRangeMin=0, chartRangeMax=50)
)
)
) %>%
formattable() %>%
formattable::as.htmlwidget() %>%
modifyList(
list(dependencies = c(
htmlwidgets:::getDependency("sparkline")
))
)
mtcars %>%
group_by(cyl) %>%
summarise(
hp = as.character(
as.tags(
sparkline(hp, type="box", chartRangeMin=0, chartRangeMax=400)
)
),
mpg = as.character(
as.tags(
sparkline(
round(density(mpg,from=0,to=tail(pretty(mtcars$mpg),1))$y,2),
type="line"
)
)
)
) %>%
formattable() %>%
formattable::as.htmlwidget() %>%
modifyList(
list(dependencies = c(
htmlwidgets:::getDependency("sparkline")
))
)