I'm generating a list of cards based on user input. When I supply this list of cards to layout_columns() it thinks it's one element and doesn't adjust the layout of the cards correctly. Specifically, it applies the width but only places one card per row. I also tried to supply do.call(tagList, list_of_cards) to layout_columns() but still same problem. See example in screenshot below when I add col_widths = rep(6, list_of_cards) I get the error Warning: Truncating number of widths at 'md' breakpoint to match number of elements. • widths: 3 • elements: 1. Repro code below.
library(shiny)
library(tidyverse)
library(bslib)
library(thematic)
# Define UI for application that draws a histogram
ui <- page_sidebar(
# Set the CSS theme
theme = bs_theme(bootswatch = "lumen",
version = 5
),
# Add sidebar elements
sidebar = sidebar(
class = "bg-secondary",
uiOutput("sidebar_content")
),
uiOutput("main_content")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# side bar
output$sidebar_content <- renderUI({
list(
selectInput("categories",
"Select categories",
choices = c("test1", "test2", "test3"),
selected = c("test1", "test2", "test3"),
multiple = TRUE),
selectInput("fy",
"Select FY",
choices = c(2023, 2024, 2025),
selected = 2024,
multiple = FALSE)
)
})
# # categories reactive
# get selected categories
categories <- reactive({ input$categories })
fy <- reactive({ input$fy })
# main contents
output$main_content <- renderUI({
req(categories())
req(fy())
# Create a list to store the card elements
cats = categories()
fy_selected = fy()
cardList <- map(1:length(cats), function(i) {
card(card_header(cats[i], class = "h6 text-success"), "sample")
})
# Return the list of card elements within layout_columns
layout_columns(col_widths = rep(6, length(cats)),
do.call(tagList, cardList))
})
}
# Run the application
shinyApp(ui = ui, server = server)
Session Info
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 4.3.2 (2023-10-31 ucrt)
os Windows 10 x64 (build 19045)
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.utf8
ctype English_United States.utf8
tz America/New_York
date 2024-02-01
rstudio 2023.12.0+369 Ocean Storm (desktop)
pandoc NA
─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
! package * version date (UTC) lib source
P bit 4.0.5 2022-11-15 [?] RSPM (R 4.3.0)
P bit64 4.0.5 2020-08-30 [?] RSPM (R 4.3.0)
P bsicons * 0.1.2 2023-11-04 [?] RSPM (R 4.3.0)
P bslib * 0.6.1 2023-11-28 [?] CRAN (R 4.3.2)
P cachem 1.0.8 2023-05-01 [?] CRAN (R 4.3.2)
P cli 3.6.1 2023-03-23 [?] CRAN (R 4.3.2)
P colorspace 2.1-0 2023-01-23 [?] RSPM (R 4.3.0)
P crayon 1.5.2 2022-09-29 [?] CRAN (R 4.3.2)
P curl 5.2.0 2023-12-08 [?] RSPM (R 4.3.0)
P devtools 2.4.5 2022-10-11 [?] RSPM (R 4.3.0)
P digest 0.6.33 2023-07-07 [?] CRAN (R 4.3.2)
P dplyr * 1.1.4 2023-11-17 [?] RSPM (R 4.3.0)
P ellipsis 0.3.2 2021-04-29 [?] CRAN (R 4.3.2)
P fansi 1.0.6 2023-12-08 [?] RSPM (R 4.3.0)
P farver 2.1.1 2022-07-06 [?] RSPM (R 4.3.0)
P fastmap 1.1.1 2023-02-24 [?] CRAN (R 4.3.2)
P forcats * 1.0.0 2023-01-29 [?] RSPM (R 4.3.0)
P fs 1.6.3 2023-07-20 [?] CRAN (R 4.3.2)
P generics 0.1.3 2022-07-05 [?] RSPM (R 4.3.0)
P ggiraph * 0.8.8 2023-12-09 [?] RSPM (R 4.3.0)
P ggplot2 * 3.4.4 2023-10-12 [?] RSPM (R 4.3.0)
P glue * 1.6.2 2022-02-24 [?] CRAN (R 4.3.2)
P gsheet * 0.4.5 2020-04-07 [?] RSPM (R 4.3.0)
P gtable 0.3.4 2023-08-21 [?] RSPM (R 4.3.0)
P hms 1.1.3 2023-03-21 [?] RSPM (R 4.3.0)
P htmltools 0.5.7 2023-11-03 [?] CRAN (R 4.3.2)
P htmlwidgets 1.6.4 2023-12-06 [?] RSPM (R 4.3.0)
P httpuv 1.6.13 2023-12-06 [?] CRAN (R 4.3.2)
P jquerylib 0.1.4 2021-04-26 [?] CRAN (R 4.3.2)
P jsonlite 1.8.8 2023-12-04 [?] CRAN (R 4.3.2)
P knitr 1.45 2023-10-30 [?] RSPM (R 4.3.0)
P later 1.3.2 2023-12-06 [?] CRAN (R 4.3.2)
P lifecycle 1.0.4 2023-11-07 [?] CRAN (R 4.3.2)
P lubridate * 1.9.3 2023-09-27 [?] RSPM (R 4.3.0)
P magrittr 2.0.3 2022-03-30 [?] CRAN (R 4.3.2)
P memoise 2.0.1 2021-11-26 [?] CRAN (R 4.3.2)
P mime 0.12 2021-09-28 [?] CRAN (R 4.3.1)
P miniUI 0.1.1.1 2018-05-18 [?] RSPM (R 4.3.0)
P munsell 0.5.0 2018-06-12 [?] RSPM (R 4.3.0)
P pillar 1.9.0 2023-03-22 [?] RSPM (R 4.3.0)
P pkgbuild 1.4.3 2023-12-10 [?] RSPM (R 4.3.0)
P pkgconfig 2.0.3 2019-09-22 [?] RSPM (R 4.3.0)
P pkgload 1.3.4 2024-01-16 [?] RSPM (R 4.3.0)
P profvis 0.3.8 2023-05-02 [?] RSPM (R 4.3.0)
P promises 1.2.1 2023-08-10 [?] CRAN (R 4.3.2)
P purrr * 1.0.2 2023-08-10 [?] RSPM (R 4.3.0)
P R6 2.5.1 2021-08-19 [?] CRAN (R 4.3.2)
P Rcpp 1.0.11 2023-07-06 [?] CRAN (R 4.3.2)
P readr * 2.1.5 2024-01-10 [?] RSPM (R 4.3.0)
P remotes 2.4.2.1 2023-07-18 [?] RSPM (R 4.3.0)
renv 1.0.3 2023-09-19 [1] CRAN (R 4.3.2)
P rlang 1.1.2 2023-11-04 [?] CRAN (R 4.3.2)
P rstudioapi 0.15.0 2023-07-07 [?] RSPM (R 4.3.0)
P sass 0.4.8 2023-12-06 [?] CRAN (R 4.3.2)
P scales * 1.3.0 2023-11-28 [?] RSPM (R 4.3.0)
P sessioninfo 1.2.2 2021-12-06 [?] RSPM (R 4.3.0)
P shiny * 1.8.0 2023-11-17 [?] CRAN (R 4.3.2)
P stringi 1.8.3 2023-12-11 [?] RSPM (R 4.3.0)
P stringr * 1.5.1 2023-11-14 [?] RSPM (R 4.3.0)
P systemfonts 1.0.5 2023-10-09 [?] RSPM (R 4.3.0)
P thematic * 0.1.4 2023-11-04 [?] RSPM (R 4.3.0)
P tibble * 3.2.1 2023-03-20 [?] RSPM (R 4.3.0)
P tidyr * 1.3.1 2024-01-24 [?] RSPM (R 4.3.0)
P tidyselect 1.2.0 2022-10-10 [?] RSPM (R 4.3.0)
P tidyverse * 2.0.0 2023-02-22 [?] RSPM (R 4.3.0)
P timechange 0.3.0 2024-01-18 [?] RSPM (R 4.3.0)
P tzdb 0.4.0 2023-05-12 [?] RSPM (R 4.3.0)
P urlchecker 1.0.1 2021-11-30 [?] RSPM (R 4.3.0)
P usethis 2.2.2 2023-07-06 [?] RSPM (R 4.3.0)
P utf8 1.2.4 2023-10-22 [?] RSPM (R 4.3.0)
P uuid 1.2-0 2024-01-14 [?] RSPM (R 4.3.0)
P vctrs 0.6.5 2023-12-01 [?] RSPM (R 4.3.0)
P vroom 1.6.5 2023-12-05 [?] RSPM (R 4.3.0)
P withr 2.5.2 2023-10-30 [?] CRAN (R 4.3.2)
P xfun 0.41 2023-11-01 [?] RSPM (R 4.3.0)
P xtable 1.8-4 2019-04-21 [?] CRAN (R 4.3.2)
P yaml 2.3.8 2023-12-11 [?] RSPM (R 4.3.0)
[1] C:/Users/oliver/Documents/GitHub/budget_burn_rate/renv/library/R-4.3/x86_64-w64-mingw32
[2] C:/Users/oliver/AppData/Local/R/cache/R/renv/sandbox/R-4.3/x86_64-w64-mingw32/1e360f03
P ── Loaded and on-disk path mismatch.
@gadenbuie answered on the bslib github:
use
!!!cardListinstead ofdo.call(tagList, cardList)