Create a carousel in Rmarkdown?

谁说我不能喝 提交于 2020-08-09 10:23:26

问题


Is there any quick and easy way to create a simple carousel in an Rmarkdown doc?

What I know so far

I found slickr but run into errors setting options and knitting (the errors could be specific to me / mac - I am not sure at this point).

I believe it would be possible to hard code html/javascript into the RMarkdown doc i.e. the same way a carousel would be done in any other (regular) html document (i.e. using the html code here)- but I wonder if there's a native (R) way?

Example use

In my particular use case, I'm trying to display multiple complicated ggplots which are each sufficiently complex to make them require their own space (i.e. not faceted or grid.arrange as the size of each plot will get too small to read

Notes

Here is the slickr code I tried

library(texPreview)
library(slickR)


objpath <- file.path(getwd(),"slickr_files/figure-html")

if(!dir.exists(objpath)) { dir.create(objpath,recursive = TRUE) }

tex_opts$set(
  fileDir    = objpath, # path to save output
  returnType = 'html', # return images ready for html 
  imgFormat  = 'png' # return png images
)


knitr::kable(mtcars,'latex') %>%
  texPreview::tex_preview(stem = 'kable-1')
# ! LaTeX Error: File `standalone.cls' not found.

A side note, if there's a better way of providing many (e.g. > 3) large, detailed plots that doesn't involve faceting, grid.arrange, or (my current preferred option) tabbing, please give a suggestion as a comment


回答1:


The example works fine for me. Be sure to save your plots in the folder slickr_files/figure-html.

Then run:

```{r}
slickR::slickR(
    list.files(objpath,full.names = TRUE,pattern = 'png'),
    height = 200,
    width = '95%')
```


来源:https://stackoverflow.com/questions/61313078/create-a-carousel-in-rmarkdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!