Skip to content

Instantly share code, notes, and snippets.

@jcheng5
Last active August 29, 2015 13:56
Show Gist options
  • Save jcheng5/9200668 to your computer and use it in GitHub Desktop.
Save jcheng5/9200668 to your computer and use it in GitHub Desktop.
CSS DSL for R
library(shiny)
css <- local({
cssRules <- function(rules) {
paste(
' ',
gsub('.', '-', names(rules), fixed = TRUE),
': ',
rules,
';',
sep = '')
}
function(...) {
selectors <- list(...)
if (length(selectors) == 0)
return(NULL)
lines <- unlist(lapply(1:length(selectors), function(i) {
name <- names(selectors)[[i]]
value <- selectors[[i]]
c(paste(name, ' {', sep=''),
cssRules(value),
'}')
}))
do.call(tags$style, c(list(type='text/css'), lines))
}
})
# tests
tags$style(type="text/css",
".search {",
" font-family: Source Sans Pro;",
" font-size: 12px;",
"}",
"#foo.bar span a {",
" margin-top: 8px;",
" margin-bottom: 0;",
"}"
)
css(
.search = c(
font.family = "Source Sans Pro",
font.size = "12px"
),
"#foo.bar span a" = c(
margin.top = "8px",
margin.bottom = 0
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment