Linne: Linne

Description Attributes Methods Examples

Description

Generate CSS from R code. Initialise a new CSS environment with new, use rule to define CSS rules.

Attributes

There are hundreds of attributes to pass to the three-dot construct (...), a comprehensive list of them can be found on w3schools.

Note that Linne accepts camelCase for convenience, e.g.: font-size or fontSize.

Methods

Public methods


Method define()

Usage
Linne$define(...)
Arguments
...

Named variables to define.

Details

Define variables.

Returns

Self: the Linne object.

Examples
Linne$new()$define(baseColor = "blue")

Method rule()

Usage
Linne$rule(selector, ...)
Arguments
selector

An object of class selector as returned by the sel_* family of functions.

...

Declarations: properties and their values. This accepts camelcase, e.g.: font-style or fontStyle.

Details

Rule

Define a CSS rule.

Returns

Self: the Linne object.

Examples
Linne$new()$rule(sel_id("myButton"), color = "blue", fontSize = 50)

Method build()

Usage
Linne$build()
Details

Builds CSS

Builds the CSS from definitions and rules.

Examples
Linne$
 new()$
 define(primary_color = 'red')$
 rule(
   sel_id("myButton"), 
   color = primary_color, 
   fontSize = 50
 )$
 rule(
   sel_class("container"),
   backgroundColor = primary_color
 )$
 build()

Method get_css()

Usage
Linne$get_css(build = TRUE)
Arguments
build

Whether to build the CSS with the build method.

Details

Retrieve the CSS

Returns

A string.

Examples
Linne$new()$rule(sel_id("myId"), fontSize = 20)$get_css()

Method show_css()

Usage
Linne$show_css(build = TRUE)
Arguments
build

Whether to build the CSS with the build method.

Details

Prints Generated CSS

Examples
Linne$new()$rule(sel_id("myButton"), color = "blue")$show_css()

Method import()

Usage
Linne$import(url)
Arguments
url

URL to import.

Details

Import

Import from a url or path.

Examples
Linne$new()$import('https://fonts.googleapis.com/css2?family=Roboto')

Method include()

Usage
Linne$include(build = TRUE)
Arguments
build

Whether to build the CSS with the build method.

Details

Include in Shiny

Includes the CSS in shiny, place the call to this method anywhere in the shiny UI.

Returns

htmltools::tags

Examples
# generate CSS
css <- Linne$
  new()$
  define(grey = '#c4c4c4')$
  rule(
    sel_id("myButton"), 
    backgroundColor = 'red', 
    fontSize = 20,
    color = grey
  )$
  rule(
    sel_class("aClass"),
    color = grey
  )

# include in an app
library(shiny)

ui <- fluidPage(
  css$include(),
  h1("Some text", class = "aClass"),
  actionButton("myButton", "Am I red?", class = "aClass")
)

server <- function(input, output){
  output$myPlot <- renderPlot(plot(cars))
}

if(interactive())
 shinyApp(ui, server)


Method write()

Usage
Linne$write(path = "style.css", pretty = FALSE, build = TRUE)
Arguments
path

Path to file.

pretty

Whether to keep tabs and newlines.

build

Whether to build the CSS with the build method.

Details

Save

Write the CSS to file.

Examples
if(interactive()) 
 Linne$new()$rule(sel_id("id"), fontStyle = "italic")$write("styles.css")

Method print()

Usage
Linne$print()
Details

Print

Prints information on the Linne object.


Method inject()

Usage
Linne$inject(build = TRUE, session = shiny::getDefaultReactiveDomain())
Arguments
build

Whether to build the CSS with the build method.

session

A valid shiny session.

Details

Inject CSS

Dynamically inject CSS from the server of a shiny application.

Examples
library(shiny)

ui <- fluidPage(
  useLinne(),
  actionButton("change", "Change me!")
)

server <- function(input, output){

  linne <- Linne$
    new()$
    rule(
      sel_id("change"),
      color = "white",
      backgroundColor = "black"
    )

  observeEvent(input$change, {
    linne$inject()
  })

}

if(interactive())
 shinyApp(ui, server)

Method clone()

The objects of this class are cloneable with this method.

Usage
Linne$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
## ------------------------------------------------
## Method `Linne$define`
## ------------------------------------------------

Linne$new()$define(baseColor = "blue")

## ------------------------------------------------
## Method `Linne$rule`
## ------------------------------------------------

Linne$new()$rule(sel_id("myButton"), color = "blue", fontSize = 50)

## ------------------------------------------------
## Method `Linne$build`
## ------------------------------------------------

Linne$
 new()$
 define(primary_color = 'red')$
 rule(
   sel_id("myButton"), 
   color = primary_color, 
   fontSize = 50
 )$
 rule(
   sel_class("container"),
   backgroundColor = primary_color
 )$
 build()

## ------------------------------------------------
## Method `Linne$get_css`
## ------------------------------------------------

Linne$new()$rule(sel_id("myId"), fontSize = 20)$get_css()

## ------------------------------------------------
## Method `Linne$show_css`
## ------------------------------------------------

Linne$new()$rule(sel_id("myButton"), color = "blue")$show_css()

## ------------------------------------------------
## Method `Linne$import`
## ------------------------------------------------

Linne$new()$import('https://fonts.googleapis.com/css2?family=Roboto')

## ------------------------------------------------
## Method `Linne$include`
## ------------------------------------------------

# generate CSS
css <- Linne$
  new()$
  define(grey = '#c4c4c4')$
  rule(
    sel_id("myButton"), 
    backgroundColor = 'red', 
    fontSize = 20,
    color = grey
  )$
  rule(
    sel_class("aClass"),
    color = grey
  )

# include in an app
library(shiny)

ui <- fluidPage(
  css$include(),
  h1("Some text", class = "aClass"),
  actionButton("myButton", "Am I red?", class = "aClass")
)

server <- function(input, output){
  output$myPlot <- renderPlot(plot(cars))
}

if(interactive())
 shinyApp(ui, server)


## ------------------------------------------------
## Method `Linne$write`
## ------------------------------------------------

if(interactive()) 
 Linne$new()$rule(sel_id("id"), fontStyle = "italic")$write("styles.css")

## ------------------------------------------------
## Method `Linne$inject`
## ------------------------------------------------

library(shiny)

ui <- fluidPage(
  useLinne(),
  actionButton("change", "Change me!")
)

server <- function(input, output){

  linne <- Linne$
    new()$
    rule(
      sel_id("change"),
      color = "white",
      backgroundColor = "black"
    )

  observeEvent(input$change, {
    linne$inject()
  })

}

if(interactive())
 shinyApp(ui, server)

linne documentation built on Jan. 8, 2021, 2:24 a.m.