【问题标题】:Saving HTMLWidget with links to HTML dependencies instead of embedding them保存带有指向 HTML 依赖项的链接的 HTMLWidget,而不是嵌入它们
【发布时间】:2021-02-08 17:12:34
【问题描述】:

我使用saveWidget() 函数保存了我的ggplotly 对象。如果我使用selfcontained=TRUE 选项执行此操作,则所有 HTML 依赖项(javascript 库和 CSS 样式)都保存在 HTML 文件中,使其非常大。如果我使用 selfcontained=FALSE,这些依赖项将保存在单独的 _file 文件夹中,并从 HTML 文件链接:

<script src="testA_files/htmlwidgets-1.5.3/htmlwidgets.js"></script>
<script src="testA_files/plotly-binding-4.9.2.1/plotly.js"></script>
<script src="testA_files/typedarray-0.1/typedarray.min.js"></script>
<script src="testA_files/jquery-3.5.1/jquery.min.js"></script>
<link href="testA_files/crosstalk-1.1.1/css/crosstalk.css" rel="stylesheet" />
<script src="testA_files/crosstalk-1.1.1/js/crosstalk.min.js"></script>
<link href="testA_files/plotly-htmlwidgets-css-1.52.2/plotly-htmlwidgets.css" rel="stylesheet" />
<script src="testA_files/plotly-main-1.52.2/plotly-latest.min.js"></script>

例如,对于jQuery,我知道我可以使用code.jquery.com 存储库并将我的调用替换为src="https://code.jquery.com/jquery-3.5.1.min.js"。所有其他依赖项是否有类似的公共存储库?

【问题讨论】:

    标签: ggplotly htmlwidgets


    【解决方案1】:

    在您列出的所有依赖项中,plotly 可能是最大的。最新的plotly指的是这个cdn:

    https://cdn.plot.ly/plotly-basic-2.5.1.min.js
    

    您可以通过查看绘图依赖项来看到这一点,如下所示:

    p <- ggplotly(p) %>% partial_bundle(local = FALSE)
    p$dependencies
    

    【讨论】:

    • 谢谢,很有帮助!我希望其他软件包也有类似的 $dependencies 可用...
    猜你喜欢
    • 2018-04-21
    • 1970-01-01
    • 2021-01-01
    • 2016-01-14
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    相关资源
    最近更新 更多