在RMarkdown中呈现生成的HTML。

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

Render computed HTML in RMarkdown

问题

你可以使用以下方法告诉RMarkdown将outputFromAFunction作为有颜色的字母A呈现,而不是简单地将HTML打印为文本:

  1. ```{r, results='asis'}
  2. cat(outputFromAFunction)
  1. 这将允许RMarkdown渲染`outputFromAFunction`的内容,而不会移除闭合的`span`标签,并以HTML格式呈现。
  2. <details>
  3. <summary>英文:</summary>
  4. I have a function that produces some html and I want RMarkdown to render the html.
  5. ````markdown
  6. ```{r}
  7. outputFromAFunction &lt;- &#39;&lt;span style=&quot;background-color: #A6CEE3&quot;&gt;A&lt;/span&gt;&#39;
  8. outputFromAFunction
  1. How do I tell rmarkdown to render `outputFromAFunction` as the colored letter A instead of simply printing the html as text.
  2. 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.
  3. I need to render a html page not shiny.
  4. </details>
  5. # 答案1
  6. **得分**: 1
  7. 使用 `results='asis'` 并使用 `cat` 输出值:
  8. ```
  9. ```{r results='asis'}
  10. outputFromAFunction <- '<span style="background-color: #A6CEE3">A</span>'
  11. cat(outputFromAFunction)
  12. ```
  13. ```
  14. <details>
  15. <summary>英文:</summary>
  16. Use `results=&#39;asis&#39;` and `cat` the value:
  1. outputFromAFunction &lt;- &#39;&lt;span style=&quot;background-color: #A6CEE3&quot;&gt;A&lt;/span&gt;&#39;
  2. cat(outputFromAFunction)
  1. </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:

确定