简体   繁体   English

将纯 HTML 强制转换为 Shiny.tags

[英]Coercing plain HTML to shiny.tags

How do you convert a vector with plain HTML to a nested shiny tag list?如何将带有纯 HTML 的矢量转换为嵌套的闪亮标签列表?

Rep. Example代表示例

library(shiny)
library(htmltools)

html_str <- '<div><h1>Headline</h1><p>Text</p></div>'

Both htmltools::as.tags() and htmltools::tagList() don't seem to work. htmltools::as.tags()htmltools::tagList()似乎都不起作用。 Although this post shows an example on how one could convert html to shiny.tags, I refuse to believe that there isn't a simpler solution provided by any of the major packages. 尽管这篇文章展示了一个关于如何将 html 转换为 Shiny.tags 的示例,但我拒绝相信任何主要软件包都没有提供更简单的解决方案。

Desired Output期望输出

result <- tags$div(tags$h1("Headline"), tags$p("Text"))

> class(result)
[1] "shiny.tag"

I've made a Shiny app to perform this task.我制作了一个 Shiny 应用程序来执行此任务。 It uses the JavaScript library himalaya .它使用 JavaScript 库himalaya It is available in my package html2R .它在我的包html2R 中可用。 See ?html2R for usage examples.有关使用示例,请参阅?html2R

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM