[英]R Obtaining a self-contained html file for tag list
I hope somebody can help me with this.我希望有人能帮我解决这个问题。 I have a package that uses htmltools and reactable to produce html reports for some operations, for example:
我有一个使用 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)
In this case i'm using the prependContent function from htmlwidget since reactable is a widget.在这种情况下,我使用 htmlwidget 的 prependContent 函数,因为 reactable 是一个小部件。 When I print this widget (either in RStudio Viewer or the browser) everything works fine, but I'd also like to export this widget in a self contained html file on disk at a specified path.
当我打印这个小部件(在 RStudio 查看器或浏览器中)时,一切正常,但我还想将此小部件导出到磁盘上指定路径的自包含 html 文件中。 So in my function code I do:
所以在我的函数代码中,我这样做:
htmlwidgets::saveWidget(widg, export_widget_path)
From documentation by default the selfcontained parameter is set to TRUE and I have pandoc installed correctly but this happens:默认情况下,从文档中 selfcontained 参数设置为 TRUE 并且我已经正确安装了 pandoc 但发生了这种情况:
Even if I opt for self contained options a files folder is produced and when I open the file a portion of it is wrongly rendered:即使我选择自包含选项,也会生成一个文件夹,当我打开文件时,它的一部分会被错误呈现:
This doesn't happen when the widget is printed (either in viewer or browser)打印小部件时不会发生这种情况(在查看器或浏览器中)
I also tried to change this我也试图改变这一点
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)
with this有了这个
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
)
)
Obtaining a tag.shiny object but of course it doesn't work with htmlwidgets::saveWidget, I have to use htmltools::save_html which doesn't produce a self-contained file.获取 tag.shiny 对象,但当然它不适用于 htmlwidgets::saveWidget,我必须使用 htmltools::save_html ,它不会产生自包含文件。
I know there is an option with pandoc to convert html to self contained but it also produces weird results when I tried to use it (mainly graphics not rendered correctly).我知道 pandoc 有一个选项可以将 html 转换为自包含,但是当我尝试使用它时它也会产生奇怪的结果(主要是图形渲染不正确)。
Is there any way this could be done or do I have to surrender to the fact that I'll have non self-contained html files?有什么办法可以做到这一点,还是我必须屈服于我将拥有非独立 html 文件的事实? Thanks in advance
提前致谢
Have you tried setting your working directory to the location that you want to save the self-contained file?您是否尝试将工作目录设置为要保存自包含文件的位置? That is the only way that I am able to make self-contained files with
htmlwidgets::saveWidget()
.这是我能够使用
htmlwidgets::saveWidget()
制作自包含文件的唯一方法。
您需要使用 htmlwidgets::saveWidget(frameableWidget(mapdt3),'map.html') frameableWidget 将来自 widgetframe 它将 html 文件保存为自包含文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.