How to splice a list created in the server

Hi! I am struggling with the correct way of splicing a list of HTML objects (in this case, cards) created in the server side.

This is easy enough to do in the UI with the splice (!!!) operator, but in my case I need the quantity and the contents of the various cards I'm making to be created dynamically.

Here's an example with a screen shot of what I'm seeing:

library(shiny)
library(bslib)

ui <- page_fixed(
    hr(),
    layout_column_wrap(
        width = 1/10,
        !!!list(
            card("One"),
            card("Two")
        )
    ),
    hr(),
    layout_column_wrap(
        width = 1/10,
        uiOutput("cardList")
    )
    
)

server <- function(input, output, session) {
    
    output$cardList <- renderUI({
        
        list(
            card("One"),
            card("Two")
        )
        
    })
    
}

shinyApp(ui, server)

The !!! operator performed on the list of cards created directly in the UI is working exactly as it should inside of the layout_column_wrap(). However, I'm not sure how to create the same effect when passing the list of cards created in the server. I'm guessing it has to do with it not being just a list anymore since it is receiving a class with the uiOutput() function.

I have (somewhat haphazardly) tried applying the splice operator in various places with the cards created in the server with no luck.

The one idea I had was to save the list of cards created in the server as a reactive, but I don't know how to let the UI know how to access those values correctly.

I feel like I'm missing something obvious here and am hoping that someone can help me out; thanks in advance!

Hi @ttrodrigz! I'd recommend including the layout_column_wrap() call in your renderUI(), i.e. generating the entire layout on the server side:

library(shiny)
library(bslib)

ui <- page_fixed(
  uiOutput("cardList")
)

server <- function(input, output, session) {
  output$cardList <- renderUI({
    layout_column_wrap(
      width = 1 / 10,
      !!!list(card("One"), card("Two"))
    )
  })
}

shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.