I am trying to display a list of cards in a 2d grid using the function bslib::layout_column_wrap()
. However, I get a 1d grid with the cards positioned in one column instead of multiple columns. See a minimal reproducible example below:
library(tidyverse); library(htmlwidgets); library(bslib)
cards_list <- list(
card(card_body("card 1")),
card(card_body("card 2"))
)
layout_column_wrap(width=0.5, cards_list, heights_equal="all", fixed_width=T, fill=T)
When listing the elements of the list, it works fine (see below). However, this is not feasible because my list has hundreds of cards. Can anyone assist me with that?
layout_column_wrap(width=0.5, cards_list[1], cards_list[2], heights_equal="all", fixed_width=T, fill=T)
One option to pass your list of cards to layout_column_wrap
would be to use splice operator !!!
from rlang
:
library(tidyverse)
library(htmlwidgets)
library(bslib)
layout_column_wrap(
width = 0.5,
!!!cards_list,
heights_equal = "all", fixed_width = TRUE, fill = TRUE
)
Or using do.call
:
do.call(
layout_column_wrap,
c(
list(width = 0.5, heights_equal = "all", fixed_width = TRUE, fill = TRUE),
cards_list
)
)