HTML输出加载时间太长 [英] Html output takes too long to load

查看:411
本文介绍了HTML输出加载时间太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Rmarkdown的html knit输出,但是由于它很重(这是在线指南),因此打开链接时该页面花费的时间太长.我试图将rmd文件分成不同的rms子文件,如下所示,但仍然无法得到结果.谢谢

I have this html knit output from Rmarkdown but since it is pretty heavy (it is an online guide), the page takes too long to show up when opening the link. I tried to divide the rmd file into distinct rms sub files as below shown but I still can't get the result. Thank you

title: "my_file"
author: "me"
date: "26/02/2020"
output:
  html_document:
    toc: yes
    toc_depth: 3
    toc_float:
      collapsed: yes
      smooth_scroll: yes
  word_document: default
---


```{r child = 'child0.Rmd'}
```

```{r child = 'child1.Rmd'}
```

```{r child = 'child2.Rmd'}
```

```{r child = 'child3.Rmd'}
```

```{r child = 'child4.Rmd'}
```

推荐答案

调查并尝试减小图片/图形的大小:与多个"html-pages"中的文本"split"并行或替代,这个想法是要在打开时间和图形(和导入的图片)的质量之间做出折衷.

Investigate and try to reduce the size of yours pictures/graphics : in parallel or alternatively to the 'split' of your text in several 'html-pages', the idea is to made a compromise between time of opening and quality of your graphics (and imported pictures).

所以,尝试:

  • 为减少由某些代码块计算出的图形的大小,请参见下面的示例.
  • 通过调整图片大小来减小导入图片的大小.
  • 要利用能够呈现svg文件的html格式,请执行以下操作:尝试在svg中编码数据的图形表示形式.不是您的外部图像,而是您的计算所产生的图形(文本+区域+颜色=某些图形在svg中比在jpg或tif中更亮").

为什么要减小文档中图片和图形的大小?如果图像以超高清渲染,则导出的文档中包含一堆图像的尺寸非常大,并且需要花费大量时间读取内存中的文件(打开),内存崩溃或冻结, etc .因此,文档中图像的大小(def)通常是减轻文档重量的关键,也许您必须针对这两种情况在代码的图像或图形"部分中进行搜索:

Why reduce the size of your pictures and graphics in your document ? If images are render in ultra high def, it's resulting in a very huge size for the exported document that contain a bunch of images, and lot of time for reading file in memory (openning), memory crash or freeze, etc. So, sizes (def) of images in a document are frequently the key for reducing the weight of a document, and maybe you'll have to search in the 'image or graphic' part of the code for these 2 cases :

1-如果在图像代码块的最开始处用Rmarkdown指示了图像的大小,请检查"fig.height"和"'fig.width'表示合理的大小,如下所示:

1- If you indicate size of an image in Rmarkdown at the very beginning of your image-codechunk, check that 'fig.height' & 'fig.width' indicates a reasonnable size, like the following :

```{r name_of_the_chunk, fig.cap="Name_of_fig", fig.height=10, fig.width=8}

2-在某些保存图形或渲染图像的代码中可能存在或与以前相同的情况,因此请确保在程序化"中指定合理的尺寸(宽度"和高度") '的方式呈现图像,如果代码块未指定尺寸,则为 ie :

2- the same case than previously is maybe present or necessary in some code that saved the graph or render the image or whatever, so ensure that you indicate for reasonable dimensions ('width' and 'height') in your 'programmatic' way to render the image, if the codechunk don't indicate a size, i.e :

svg("my.svg", width = 8,height =8) [code of your graph]

svg("my.svg", width = 8,height =8) [code of your graph]

也许在ggsave(file="myfile.svg",device = "svg",width =6,height = 6,units = "cm") [code of your graph]中设置了高度和宽度 ...或用于生成图片的任何功能.

maybe height and width are set in ggsave(file="myfile.svg",device = "svg",width =6,height = 6,units = "cm") [code of your graph] ... or whatever function you use for generate your pictures.

或者,您可以使用图形库在编织文档之前调整每个图像的大小(:ImageMagick).

Alternatively, you could use a graphic library for resizing every images before to knit your document (i.e : ImageMagick).

美好的一天

这篇关于HTML输出加载时间太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆