【发布时间】:2021-01-20 11:28:04
【问题描述】:
是否可以基于钩子创建模式?代表 R 降价:
---
title: "Modal hook"
output: html_document
---
```{r setup, include=FALSE}
library(bsplus)
library(htmltools)
library(knitr)
knit_hooks$set(modal = function(before, options, envir) {
# ???
})
```
This chunk creates a modal window
```{r, echo=FALSE}
title <- "Test"
text = "Some text."
{
sink("tmp.md")
cat('\n```r\nc(1,1)\n```', sep="")
cat('\n', text)
sink()
}
id <- "m1"
tagList(bs_modal(id = id, title = title, body = includeMarkdown("tmp.md")),
bs_button(title) %>% bs_attach_modal(id_modal = id))
```
是否有可能创建一个执行相同操作的钩子:
```{r, modal = TRUE, title = "Test", text = "Some text."}
c(1,1)
```
也应该适用于情节:
```{r, modal = TRUE, title = "Test", text = "Some text."}
plot(1:10)
```
如果modal = TRUE,基本上所有chunk的输出都应该放在modal而不是document中。
问题是如何将钩子定义为第一个块。
【问题讨论】:
-
我认为您需要为此修改输出挂钩;一个新的块挂钩是不够的。见yihui.org/knitr/hooks。
标签: html r r-markdown bootstrap-modal knitr