首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R获取标签列表自包含的html文件

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

Stack Overflow用户
提问于 2021-02-03 16:42:48
回答 2查看 210关注 0票数 0

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

代码语言:javascript
复制
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文件中。因此,在我的函数代码中,我这样做:

代码语言:javascript
复制
htmlwidgets::saveWidget(widg, export_widget_path)

在文档中,默认情况下,set参数被设置为TRUE,并且我已经正确安装了pandoc,但是发生了这种情况:

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

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

我也试着改变这一点

代码语言:javascript
复制
 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)

有了这个

代码语言:javascript
复制
 widget <- 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"
            )
        ), styled_df
    )
)

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

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

有没有办法做到这一点,或者我必须接受这样一个事实,即我将拥有非自包含的html文件?提前感谢

EN

回答 2

Stack Overflow用户

发布于 2021-05-07 01:20:47

您是否已尝试将工作目录设置为要保存自包含文件的位置?这是我能够用htmlwidgets::saveWidget()制作自包含文件的唯一方法。

票数 0
EN

Stack Overflow用户

发布于 2021-06-03 11:41:14

您需要使用htmlwidgets::saveWidget(frameableWidget(mapdt3),'map.html') frameableWidget将来自widgetframe,它会将html文件保存为自包含文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66023939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档