Although formattable
uses Boostrap as its CSS/JS
framework, we can easily use other CSS/JS
frameworks.
format_table
will provide us the HTML
.
library(formattable)
format_table(head(mtcars,1))
If the JS/CSS
dependencies have already been specified, then we can use the table.attr
to control the class
required by the framework. For instance, we can change the table to a table-striped
.
library(formattable)
format_table(
head(mtcars,2),
table.attr = "class='table table-striped'"
)
If we expect the formattable
output to be standalone, then using htmltools
, we can add dependencies and specify class
(if necessary). Here is an example adding hack.css
.
library(formattable)
library(htmltools)
library(pipeR)
format_table(
head(mtcars,10),
# this isn't necessary for hack.css
# since no special class required
# but we'll supply "" to table.attr
# to override formattable's default
# class = "table table-condensed"
table.attr = "",
formatters = list(mpg=normalize_bar())
) %>>%
# use HTML to indicate that it is html
HTML() %>>%
tagList() %>>%
attachDependencies(
htmlDependency(
name = "hack.css",
version = "0.5.0",
src = c(href="https://npmcdn.com/hack/dist"),
stylesheet = c("hack.css", "standard.css")
)
)