Create Dynamic Number Of Card Elements In Shiny FlowLayout
I like to fill an area in a shiny app with card elements. The items flow into the next row when there is not enough space. This can be achieved with flowLayout. But I do not know
Solution 1:
The comment above links to an answer that works, but there is a much easier way.
Instead of using lapply
(which makes a list, confusing flowLayout
), we can use do.call
to expand the argument.
Updated server function:
server <- function(input, output, session) {
output$cards <- renderUI({
# First make the cards
args <- lapply(1:4, function(.x) card(img.src,
.species = iris[.x, "Species"],
.sepal.length = iris[.x, "Sepal.Length"]))
# Make sure to add other arguments to the list:
args$cellArgs <- list(
style = "
width: auto;
height: auto;
margin: 5px;
")
# basically the same as flowLayout(cards[[1]], cards[[2]],...)
do.call(shiny::flowLayout, args)
})
}
Post a Comment for "Create Dynamic Number Of Card Elements In Shiny FlowLayout"