This is just a wrapper around new_gridlayout that is more explicit about its input format. Also adds the ability to absorb errors for use when parsing free text that may or may not represent a layout table.

md_to_gridlayout(layout_table, null_instead_of_error = FALSE, ...)

Arguments

layout_table

Character string with a markdown table. First row and column are reserved for sizing (any valid css sizing works). An optional grid-gap can be provided using the very first cell.

null_instead_of_error

When the input fails to be parsed as a layout, should the function return NULL instead of throwing an error? Useful for situations where you're parsing multiple tables simply want to check if a table can be parsed instead of relying on it being parsable.

...

Arguments passed on to new_gridlayout

layout_def

Either a list of elements with the id, start_row, end_row, start_col, and end_col format, or a markdown table defining a layout.

row_sizes

A character vector of valid css sizes for the height of each row in your grid as given by the main layout definition. If a single value is passed, it will be repeated for all columns. If sizes are provided both here and in the main layout then these sizes will be the ones used.

col_sizes

Same as row_sizes, but for column widths

gap_size

Valid css sizing for gap to be left between each element in your grid. Like row_sizes and col_sizes, this will win-out over a gap size provided in the main layout table.

container_height

Valid css unit determining how tall the containing element should be for this layout. Defaults to 100%. Special value of "viewport" for full-page height maps to the CSS value of 100vh if any relative units (e.g. fr or auto) are included in row sizes and auto otherwise. Values such as "auto" will let the page grow to as large as it needs to be to fit all content. This should most likely be avoided when using row heights in relative units.

alternate_layouts

A list of layouts to be used for different viewport widths. This is enables your app to adapt to different screensizes such as a phone or an ultra-wide monitor. Each entry in this list must contain a layout: or valid layout declaration (see Declaring your layout section), and width_bounds: or a list with at least one of a min and max value for when your page appears. See add_alternate_layout() for more details. If no alternate layouts are given a single-column layout will be automatically applied for mobile screens (viewports less than 600px wide). Set to NULL to avoid this.

Value

An object of class "grid_layout", which stores the layout as a matrix. This can be passed to other functions such as layout_to_css().

See also

Examples

md_to_gridlayout(
  layout_table = "
    |      |120px   |1fr    |1fr    |
    |:-----|:-------|:------|:------|
    |100px |header  |header |header |
    |1fr   |sidebar |plot_a |plot_c |
    |1fr   |sidebar |plot_b |plot_b |"
)
#> gridlayout of 5 elements: 
#>         120px   1fr    1fr   
#>   100px header  header header
#>   1fr   sidebar plot_a plot_c
#>   1fr   sidebar plot_b plot_b
#> Gap of 12px. Total height of 100%.
#> 
#> Alternate layouts:  
#>   
#>   - Width < 500px 
#>            1fr    
#>     85px  header 
#>     350px sidebar
#>     350px plot_a 
#>     350px plot_b 
#>     350px plot_c 
#>   Gap of 12px. Total height of auto.


# Can specify gap size in upper left cell
md_to_gridlayout(
  layout_table = "
    |25px  |120px  |1fr    |
    |:-----|:------|:------|
    |100px |header |header |
    |1fr   |plot   |table  |
    |1fr   |footer |footer |"
)
#> gridlayout of 4 elements: 
#>         120px  1fr   
#>   100px header header
#>   1fr   plot   table 
#>   1fr   footer footer
#> Gap of 25px. Total height of 100%.
#> 
#> Alternate layouts:  
#>   
#>   - Width < 500px 
#>            1fr   
#>     85px  header
#>     350px plot  
#>     350px footer
#>     350px table 
#>   Gap of 25px. Total height of auto.

# Don't need to follow full md table with
# header row if not desired
md_to_gridlayout(
  layout_table = "
    |25px  |120px  |1fr    |
    |100px |header |header |
    |1fr   |plot   |table  |
    |1fr   |footer |footer |"
)
#> gridlayout of 4 elements: 
#>         120px  1fr   
#>   100px header header
#>   1fr   plot   table 
#>   1fr   footer footer
#> Gap of 25px. Total height of 100%.
#> 
#> Alternate layouts:  
#>   
#>   - Width < 500px 
#>            1fr   
#>     85px  header
#>     350px plot  
#>     350px footer
#>     350px table 
#>   Gap of 25px. Total height of auto.

# Can omit sizing as well if desired
md_to_gridlayout(
  layout_table = "
    |header |header |
    |plot   |table  |
    |footer |footer |"
)
#> gridlayout of 4 elements: 
#>        1fr    1fr   
#>   auto header header
#>   auto plot   table 
#>   auto footer footer
#> Gap of 12px. Total height of 100%.
#> 
#> Alternate layouts:  
#>   
#>   - Width < 500px 
#>            1fr   
#>     85px  header
#>     350px plot  
#>     350px footer
#>     350px table 
#>   Gap of 12px. Total height of auto.