C
S
S
grid

library(cssgrid)

Simple examples

style <- "border: solid black;"
grid_layout(
  grid_item("A", area = "a", style = style),
  grid_item("B", area = "b", style = style),
  grid_item("C", area = "c", style = style),
  cols = c("1fr 2fr"), rows = c("1fr 1fr"), areas = c("a b", "a c"),
  style = style
)
A
B
C

grid_layout(
  grid_item("A", row = "1 / 3", col = "1 / 2", style = style),
  grid_item("B", row = "1 / 2", col = "2 / 3", style = style),
  grid_item("C", row = "2 / 3", col = "2 / 3", style = style),
  cols = c("1fr 2fr"), rows = c("1fr 1fr"), style = style
)
A
B
C

Tidyverse style coding

Title

Sidebar

Article A

Article B

Shiny UI

Valid units for sizing elements in shiny package are limited to px, %, em, pt, in, cm, mm, ex, or pc.

Thus, there is a difficulty when layouting one element with certain size and the other fitting to the rest of area, or split the rest of the area for more elements with variety of ratios.

This is what CSS Grid Layout supports by the fr unit.

Read button has auto width, and the rest of area is dominated by text input

grid_layout(
  shiny::textInput("url", "URL", "https://example.com", width = "100%"),
  shiny::actionButton("read", "Read"),
  rows = "auto", cols = "1fr auto", column_gap = "10px"
)

Send button has auto width, and the rest of area is divided into 1:2 ratios

grid_rowwise is an alternative to grid_layout when layouting in 1 row.

grid_rowwise will add column size “auto” in case additional grids are required.

items <- tagList(
  shiny::textInput("to", "To", width = "100%"),
  shiny::textInput("message", "Message", width = "100%"),
  shiny::actionButton("read", "Send")
)
grid_rowwise(items, cols = "1fr 2fr auto", column_gap = "10px")