在RMarkdown中呈现生成的HTML。

huangapple go评论82阅读模式
英文:

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 &lt;- &#39;&lt;span style=&quot;background-color: #A6CEE3&quot;&gt;A&lt;/span&gt;&#39;
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=&#39;asis&#39;` 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=&#39;asis&#39;` and `cat` the value:
outputFromAFunction &lt;- &#39;&lt;span style=&quot;background-color: #A6CEE3&quot;&gt;A&lt;/span&gt;&#39;
cat(outputFromAFunction)

</details>



huangapple
  • 本文由 发表于 2020年1月4日 00:39:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582164.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定