grillade-shiny: Grillade Output in Shiny

Description Usage Arguments Value Examples

Description

Grillade Output in Shiny

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
grilladeOutput(outputId, width = "100%", ...)

renderGrillade(
  expr,
  n_col = NULL,
  max_n_col = NULL,
  cols_width = NULL,
  gutter = FALSE,
  output_height = "400px",
  env = parent.frame(),
  quoted = FALSE
)

Arguments

outputId

Output variable to read from.

width

If not NULL, must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

...

Other arguments to pass to the container tag function. This is useful for providing additional classes for the tag.

expr

An expression that generates a grillade.

n_col

Number of columns, default to NULL and automatically display element with equal size in the grid.

max_n_col

Maximum number of columns, used if n_col = NULL and number of elements is unknown.

cols_width

Numeric vector, numbers of columns taken by each elements, can be a single number or a vector of same length as elements number.

gutter

Add a gutter between columns, can be TRUE/FALSE, or "l" or "xl".

output_height

Height to use for output(s), this apply to htmlwidgets and ggplot2.

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

Value

An HTML output element that can be included in Shiny UI.

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
# Generate a grillade from the server -------------------------

library(grillade)
library(shiny)

ui <- fluidPage(
  tags$h2("Grillade from server"),
  sliderInput(
    inputId = "n",
    label = "Number of elements :",
    value = 3, min = 1, max = 24
  ),
  grilladeOutput("out")
)

server <- function(input, output, session) {

  output$out <- renderGrillade({
    lapply(
      X = seq_len(input$n),
      FUN = function(i) {
        wellPanel(
          paste("Column", i),
          style = "text-align: center;"
        )
      }
    )
  })

}

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


# Matrix of htmlwidgets ---------------------------------------

library(shiny)
library(apexcharter)
library(grillade)
data("economics", package = "ggplot2")

ui <- fluidPage(
  tags$h2("Htmlwidgets matrix example with grillade"),
  grilladeOutput("charts")
)

server <- function(input, output, session) {

  make_chart <- function(data, variable) {
    apex(
      data = data,
      mapping = aes(x = date, y = !!sym(variable)),
      type = "line"
    )
  }

  output$charts <- renderGrillade({
    chart1 <- make_chart(economics, "pce")
    chart2 <- make_chart(economics, "psavert")
    chart3 <- make_chart(economics, "uempmed")
    grillade(chart1, chart2, chart3)
  })

}

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


# Generate a matrix of plots from server ----------------------

library(grillade)
library(shiny)
library(ggplot2)

ui <- fluidPage(
  tags$h2("Matrix of plots with grillade"),
  sliderInput(
    inputId = "n",
    label = "Number of plots :",
    value = 3, min = 1, max = 15
  ),
  grilladeOutput("out")
)

server <- function(input, output, session) {

  output$out <- renderGrillade({
    lapply(
      X = seq_len(input$n),
      FUN = function(i) {
        ggplot() + geom_text(aes(1, 1, label = i), size = 50)
      }
    )
  }, max_n_col = 5)

}

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

dreamRs/grillade documentation built on May 2, 2020, 11:09 a.m.