【发布时间】:2020-10-28 09:30:11
【问题描述】:
我希望能够在rmarkdown 中循环创建多个 HTML div。但是,它似乎不太好用。我要创建的是bsplus::bs_modal(),然后将这些模式附加到按钮上。
具有期望结果的最小.Rmd reprex:
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(magrittr)
```
```{r}
bsplus::bs_modal(id = paste0("button_", 1), title = paste0("modal ", 1), body = NULL)
bsplus::bs_modal(id = paste0("button_", 2), title = paste0("modal ", 2), body = NULL)
```
```{r}
bsplus::bs_button("Modal 1") %>%
bsplus::bs_attach_modal("button_1")
```
```{r}
bsplus::bs_button("Modal 2") %>%
bsplus::bs_attach_modal("button_2")
```
最小的.Rmd reprex 与我正在使用的方法,但它不起作用:
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(magrittr)
```
```{r results='asis'}
lapply(1:2, function(i) {
bsplus::bs_modal(id = paste0("button_", i), title = paste0("modal ", i), body = NULL)
})
```
```{r results='asis'}
lapply(1:2, function(i) {
bsplus::bs_button(paste0("Modal ", i)) %>%
bsplus::bs_attach_modal(paste0("button_", i))
})
```
有什么想法吗?
【问题讨论】:
标签: html r r-markdown