Query tags
As of now, the
tagQuery()
function only supports simple CSS selectors …,
,+
,~
,data-
are not covered.All available query methods:
Method | Description |
---|---|
children | Get all the direct descendants of each selected tag |
find | Get all descendants of each selected tag |
parent | Get the direct ancestors of each selected tag |
parents | Get all parents of each selected tag |
siblings | Get all siblings of each selected tag |
filter | Subset selected tags with CSS selectors or R function |
resetSelected | Reset set of selected tags to the root tag |
- Example: Access the third tab content element from a tabset panel with three tabs, a common case when building custom Shiny templates.
temp_tabs <- map(1:3, \(i) tabPanel(i, paste("Tab", i)))
tabs <- bs4Dash::tabsetPanel(.list = temp_tabs)
tabs
<div class="tabbable">
<ul class="nav nav-tabs" data-tabsetid="5946">
<li class="nav-item">
<a href="#tab-5946-1" data-toggle="tab" data-value="1" class="nav-link active" data-target="#tab-5946-1">1</a>
</li>
<li class="nav-item">
<a href="#tab-5946-2" data-toggle="tab" data-value="2" class="nav-link" data-target="#tab-5946-2">2</a>
</li>
<li class="nav-item">
<a href="#tab-5946-3" data-toggle="tab" data-value="3" class="nav-link" data-target="#tab-5946-3">3</a>
</li>
</ul>
<div class="tab-content" data-tabsetid="5946">
<div class="tab-pane active" data-value="1" id="tab-5946-1">Tab 1</div>
<div class="tab-pane" data-value="2" id="tab-5946-2">Tab 2</div>
<div class="tab-pane" data-value="3" id="tab-5946-3">Tab 3</div>
</div>
</div>
tagQuery(tabs)$
# div element with CSS class "tab-pane"
find("div.tab-pane")$
filter(\(tag, index) tagGetAttribute(tag, "data-value") == 3)$
selectedTags()
[[1]]
<div class="tab-pane" data-value="3" id="tab-5946-3">Tab 3</div>