英文:
Render computed HTML in RMarkdown
问题
你可以使用以下方法告诉RMarkdown将outputFromAFunction
作为有颜色的字母A呈现,而不是简单地将HTML打印为文本:
```{r, results='asis'}
cat(outputFromAFunction)
这将允许RMarkdown渲染`outputFromAFunction`的内容,而不会移除闭合的`span`标签,并以HTML格式呈现。
<details>
<summary>英文:</summary>
I have a function that produces some html and I want RMarkdown to render the html.
````markdown
```{r}
outputFromAFunction <- '<span style="background-color: #A6CEE3">A</span>'
outputFromAFunction
How do I tell rmarkdown to render `outputFromAFunction` as the colored letter A instead of simply printing the html as text.
I have already tried the `results='asis'` code chunk option and it removes the closing span tag and does not render the html.
I need to render a html page not shiny.
</details>
# 答案1
**得分**: 1
使用 `results='asis'` 并使用 `cat` 输出值:
```
```{r results='asis'}
outputFromAFunction <- '<span style="background-color: #A6CEE3">A</span>'
cat(outputFromAFunction)
```
```
<details>
<summary>英文:</summary>
Use `results='asis'` and `cat` the value:
outputFromAFunction <- '<span style="background-color: #A6CEE3">A</span>'
cat(outputFromAFunction)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论