I am trying to create a nested tabset ideally using purrr::walk2
. But something is missing in how I am creating the tabsets as the h2 tabs aren't joining. Here is a rmd reprex. Any way to do this in rmarkdown?
---
title: "nested-tabs"
output: html_document
date: "2022-08-25"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(purrr)
library(dplyr)
library(glue)
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
starwars <- starwars %>%
head(5)
levels <- starwars %>%
distinct(sex, homeworld)
```
# Messy output
```{r results='asis'}
walk2(levels$sex, levels$homeworld, ~{
cat(
glue(
"\n## <<.x>> {.tabset}",
.open = "<<",
.close = ">>"
),
"\n"
)
cat(glue("\n### {.y}"), "\n")
starwars %>%
filter(sex == .x, homeworld == .y)
})
```
# Desired output
```{r results='asis'}
walk(levels$sex, ~{
cat(
glue(
"\n## <<.x>> {.tabset}",
.open = "<<",
.close = ">>"
),
"\n"
)
sw_tmp <- starwars %>%
filter(sex == .x)
walk(levels$homeworld, ~{
cat(glue("\n### {.x}"), "\n")
starwars %>%
filter(homeworld == .x)
})
})
```