将html widgets example page的大小与独立的html小部件的大小进行比较:
# Code to generate the html widget
library(ggplot2)
library(plotly)
library(htmlwidgets)
p <- ggplot(data = diamonds, aes(x = cut, fill = clarity)) +
geom_bar(position = "dodge")
p <- ggplotly(p)
htmlwidgets::saveWidget(p, "path/to/my/widget.html", selfcontained = TRUE)
我正在尝试通过HTTP API将htmlwidgets投放到Web应用程序,因此这些小部件的大小值得关注。为什么自包含的htmlwidget比htmlwidgets.org示例页面大得多?我可以做些改变吗?
注意:我正在考虑生成一个非独立的html页面,splitting the page to get the data,并提供*.min.js
文件,但聚合的js文件仍然累加了几MB。
答案 0 :(得分:3)
检查时看到的数字较低,因为文件是使用gzip压缩方式压缩的,数据到达后即会压缩。
我已经运行了您的示例,数据量最大的罪魁祸首似乎是<mat-select multiple placeholder="{{element.name}}" [(value)]="selectedCol" (selectionChange)="selectionChange($event)" [disabled]="!selection.isSelected(element.id)">
<div *ngFor="let item of col">
<div *ngIf="item.Id === element.id">
<mat-option [value]="item.id">
{{item.name}}
</mat-option>
</div>
</div>
</mat-select>
,它在磁盘上占用约2.8 MB的存储空间。
要对此进行验证,可以从提供的示例链接中下载该版本,它将占用约1.7 MB的存储空间。这是不一样的,但是我在示例网页上看到的本地生成的版本和R的版本相差很多(示例:plotly-latest.min.js
,我的R:plotly.js v1.16.3
),因此很可能是由于版本之间似乎有2年的差距(文件具有版权日期范围,最大值为2016年和2018年),因此有了很大的发展。
就试图减轻文件大小的负担而言,我最好的猜测是您将要使用的HTTP API可以提供相同的gzip编码。没有其他方法可以传输较少的数据,除非您可以将不需要的文件修剪为后期处理,确定这些文件将是探索性处理。