Html output takes too long to load

前端 未结 2 1792
北恋
北恋 2021-01-24 17:24

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

2条回答
  •  不知归路
    2021-01-24 18:05

    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).

    So, try :

    • to reduce size of graphics computed by some code chunk, see below for an example.
    • to reduce the size of yours imported pictures, if they huge, by resizing them.
    • to take advantage of the html format which is able to render svg files : try encoding in svg your graphics representation of your data. Not your external images, only your computation which resulting in graphics (text + area + color = some graphics are 'lighter' in svg than in jpg or tif).

    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- 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- 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]

    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.

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

    Excellent day

提交回复
热议问题