9

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

enter image description here

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
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
Dan
  • 1,711
  • 2
  • 24
  • 39
  • 1
    For now, I don't think this can be achieved using just rmarkdown. However, you can produce an HTML document with RMarkdown and then tweak the HTML to achieve a dropdown menu. I've filed a [feature request issue](https://github.com/rstudio/rmarkdown/issues/1116) on the RMarkdown github page which goes into more detail. – bschneidr Aug 14 '17 at 14:26
  • 1
    For now, you can either tweak the HTML to produce a document or use [the bsselectR package](http://walkerke.github.io/2016/12/rmd-dropdowns/) which unfortunately seems to be in a somewhat-stalled development. – bschneidr Aug 14 '17 at 14:31
  • Thanks for opening the request @BIQS. I did not know I could do that. If you want to add the above as an answer, please do so – Dan Aug 14 '17 at 14:38

3 Answers3

13

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

enter image description here enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
6

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
```

enter image description here

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:

enter image description here

bschneidr
  • 6,014
  • 1
  • 37
  • 52
2

I got the same problem and I found this fantastic link. Changing the _site.yml as follows will help. But make sure - are inline, there is a space between - and text and click Tab for the - text under the menu:

name: my-website
output_dir: docs
navbar:
  title: My Website
  left:
  - text: Home
    href: index.html
  - text: Readings
    menu:
    - text: Module 1
      href: readings-module1.html
    - text: Module 2
      href: ./insert_a.pdf

enter image description here

Seyma Kalay
  • 2,037
  • 10
  • 22