Search code examples
rshinybslib

Shiny Module for bslib::card -- where can I specify the id?


I would like to build a shiny module whose UI part is a card from bslib. Like

my_mod_ui <- function(id) {
    ns <- shiny::NS(id)
    bslib::card(
        full_screen = TRUE, 
        bslib::card_header("My Title"), 
        bslib::layout_sidebar(
            sidebar = bslib::sidebar(
                open=TRUE,
                "Sidebar"
            ), 
            "Main contents"
        )
    )
}

Now the question I have is: where does the id argument go? There seems no named parameter in bslib::card() for this.

The background is that I want two cards with the same (but customizable) structure side-by-side in my dashboard. I think that a module would be the best way to do this.


Solution

  • From the help documents of bslib::card

    ... Unnamed arguments can be any valid child of an htmltools tag (which includes card items such as card_body(). Named arguments become HTML attributes on returned UI element.

    Which means just pass an id argument

    bslib::card(
      id = "myId",
      ...other arguments...
    )