How to add dropdown menu on tab / tabset [rmarkdown / bootstrap]

故事扮演 提交于 2020-03-17 09:33:21

问题


Documentation for Bootswatch suggests I can use a dropdown menu from a tab in a tabset:

How can I achieve this with Rmarkdown? I've tried:

# SECTION 1 {.tabset .tabset-fade}

## Section 1.1 

## Section 1.2 {????something here?????}
 ### Section 1.2.1  <<<<<<<<< want this to appear under the dropdown menu

回答1:


This is now available within the development version of rmarkdown, which you can install this via devtools::install_github("rstudio/rmarkdown"). To add a dropdown menu, you must add .tabset-dropdown to the class header as follows:

---
output: html_document
---

# Heading {.tabset .tabset-dropdown}

## Dropdown 1

## Dropdown 2

## Dropdown 3 

## Dropdown 4




回答2:


For now, I don't think this can be done using just rmarkdown. However, you can produce an HTML document with a tabset section using rmarkdown and then tweak the HTML to convert the tab set to a dropdown menu. Alternatively, you can use the bsselectR package, which is unfortunately still in a somewhat-stalled development.

Below is an example of how you'd make an HTML document with rmarkdown and replace a tab set with a dropdown menu.

First, you'd write your rmarkdown document and then knit it to HTML.

---
title: "Tabset Example"
output: html_document
---

# The Tabset Section {.tabset .tabset-fade}

## First Tab
Here is the first tab's content.

## Second Tab
Here is the second tab's content
```

Then, in the resultant HTML file, you'd find this section of HTML:

<ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active">
        <a role="tab" data-toggle="tab" href="#first-tab" aria-controls="first-tab">First Tab</a>
    </li>
    <li role="presentation">
        <a role="tab" data-toggle="tab" href="#second-tab" aria-controls="second-tab">Second Tab</a>
    </li>
</ul>

and replace it with this HTML:

 <ul class="nav nav-tabs" role="tablist">
     <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
          Choose a Tab <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          <li class=""><a href="#first-tab" data-toggle="tab" aria-expanded="false" aria-controls="first-tab">First Tab</a></li>
          <li class=""><a href="#second-tab" data-toggle="tab" aria-expanded="false" aria-controls="second-tab">Second Tab</a></li>
        </ul>
     </li>
</ul>

Which should result in your tab set appearing as a dropdown menu, such as the following:



来源:https://stackoverflow.com/questions/43956378/how-to-add-dropdown-menu-on-tab-tabset-rmarkdown-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!