This function creates a tabbed interface where each tab has dynamically generated content.
Arguments
- names
A character vector of tab labels.
- fun
A function that generates the content for each tab. It must take an index (`i`) as the first argument.
- groupname
A unique string to group the radio inputs (default is generated automatically).
- checked
The index of the tab that should be pre-selected (default is `1`).
- ...
Additional arguments passed to `fun`.
Examples
tab_labels <- c("Tab1", "Tab2", "Tab3")
tab_content_fun <- function(i, extra_text = "") {
htmltools::tagList(
htmltools::tags$p(paste("Content for tab:", tab_labels[i], extra_text)),
htmltools::tags$img(src = paste0("plot_", i, ".png"), width = "100%")
)
}
tabs(tab_labels, tab_content_fun, checked = 2, extra_text = "Additional details")
#> <div class="tabs">
#> <div class="tab-buttons tc-tab-buttons">
#> <input type="radio" id="CVPEAMMHTU-Tab1" name="CVPEAMMHTU"/>
#> <label for="CVPEAMMHTU-Tab1">Tab1</label>
#> <input type="radio" id="CVPEAMMHTU-Tab2" name="CVPEAMMHTU" checked="checked"/>
#> <label for="CVPEAMMHTU-Tab2">Tab2</label>
#> <input type="radio" id="CVPEAMMHTU-Tab3" name="CVPEAMMHTU"/>
#> <label for="CVPEAMMHTU-Tab3">Tab3</label>
#> </div>
#> <div class="tab-content">
#> <div>
#> <p>Content for tab: Tab1 Additional details</p>
#> <img src="plot_1.png" width="100%"/>
#> </div>
#> <div>
#> <p>Content for tab: Tab2 Additional details</p>
#> <img src="plot_2.png" width="100%"/>
#> </div>
#> <div>
#> <p>Content for tab: Tab3 Additional details</p>
#> <img src="plot_3.png" width="100%"/>
#> </div>
#> </div>
#> </div>