R 获取标签列表的自包含 html 文件

问题描述

希望有人能帮我解决这个问题。我有一个使用 htmltools 和 reactable 为某些操作生成 html 报告的包,例如:

columns_def <- list(
    ProjectID = reactable::colDef(
        align = "right",style = list(
            color = "#9e9e9e",fontWeight = "800",borderRight = "2px solid #E6E6E6"
        ),minWidth = 60
    ),concatenatePoolIDSeqRun = reactable::colDef(
        minWidth = 100
    ),Found = reactable::colDef(
        maxWidth = 100,align = "center",style = function(value) {
            color <- if (value == TRUE) {
                "#6afc21"
            } else {
                "#d61e1e"
            }
            list(
                color = color,paddingLeft = "15px",fontWeight = "bold"
            )
        },cell = function(value) {
            if (value == TRUE) "\u2713" else "\u2718"
        }
    ),Path = reactable::colDef(
        minWidth = 200
    )
)

styled_df <- .generate_react_table(checker_df,defaultSorted = list(Found = "asc"),columns = columns_def
)
 widget_text <- htmltools::tags$html(
    htmltools::tags$head(
        htmltools::tags$style(.widget_css())
    ),htmltools::tags$body(
        htmltools::h1("IMPORT ASSOCIATION FILE REPORT"),htmltools::h2("ALIGNMENT RESULTS"),htmltools::div(
            id = "section-content",htmltools::div("Results of alignment between file system and","association file. If some folders are not found","they will be ignored until the problem is fixed","and the association file re-imported.",id = "subtitle"
            )
        )
    )
)
widget <- htmlwidgets::prependContent(styled_df,widget_text)

在这种情况下,我使用 htmlwidget 的 prependContent 函数,因为 reactable 是一个小部件。当我打印这个小部件(在 RStudio 查看器或浏览器中)时,一切正常,但我还想将此小部件导出到磁盘上指定路径的自包含 html 文件中。所以在我的函数代码中,我这样做:

htmlwidgets::saveWidget(widg,export_widget_path)

默认情况下,从文档中 selfcontained 参数设置为 TRUE,我已经正确安装了 pandoc,但发生了这种情况:

enter image description here

即使我选择自包含选项,也会生成一个文件夹,当我打开文件时,其中的一部分会被错误呈现:

enter image description here

打印小部件时不会发生这种情况(在查看器或浏览器中)

enter image description here

我也试图改变这一点

 widget_text <- htmltools::tags$html(
    htmltools::tags$head(
        htmltools::tags$style(.widget_css())
    ),widget_text)

有了这个

 widget <- htmltools::tags$html(
    htmltools::tags$head(
        htmltools::tags$style(.widget_css())
    ),id = "subtitle"
            )
        ),styled_df
    )
)

获得 tag.shiny 对象,但当然它不适用于 htmlwidgets::saveWidget,我必须使用 htmltools::save_html,它不会产生自包含文件。

我知道 pandoc 有一个选项可以将 html 转换为自包含,但当我尝试使用它时也会产生奇怪的结果(主要是图形渲染不正确)。

有什么办法可以做到这一点,还是我必须屈服于我将拥有非独立 html 文件的事实?提前致谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)