5 min read

Embedding a Trelliscope Widget in GitHub Pages


a trellis for a plant
R package trelliscopejs

View raw source for this post

Summary

By default, Hugo automatically takes the first 70 words of your content as its summary and stores it into the .Summary page variable for use in your templates. You may customize the summary length by setting summaryLength in your site configuration or you can set it in the front matter.

Table of Contents

Overview

I just learned about the R trelliscope package. The question was whether a trelliscope widget could be embedded into a github page. The widget could be embedded into this blog by first creating a separate repository and then inserting an iframe on the blog post.

Step 1 - Create Repo

The address for the repository is here. The key is the script within the ./R folder.

Step 2 - Create Trelliscope Plot

This code was taken from the “Getting Started” page of the package’s documentation.

qplot(year, lifeExp, data = gapminder) + xlim(1948, 2011) + ylim(10, 95) + theme_bw() +
    facet_trelliscope(~country + continent, nrow = 2, ncol = 7, width = 300)

Step 3 - Save Widget to Docs

Create a ./docs folder. dir.create("./docs") should work. The place where I struggled was collecting and saving the widget. The files are kept in the temporary directory. The code was included in the issues thread of the package. (You can find it here.)

The strategy was to copy the files, libraries and directories generated from the package and place them in the docs folder. That was accomplished with the code below:

trell_files <- list.files("/tmp/gap", full.names = T)

file.copy(from = trell_files, to = "./docs", recursive = T)

Step 5 - Add iframe

Find the url address where GitHub published the page and insert it into the src attribute.

<iframe src="https://robwiederstein.github.io/trelliscope/#display=by_country_continent&nrow=2&ncol=7&arr=row&pg=1&labels=country&sort=country;asc&filter=&sidebar=&fv=" width=600, height=400 title="Trelliscope Plot"></iframe>

Conclusion

The trelliscope package can provide insight on high-dimensional data. I’m really interested to see if it will work into a modeling workflow where the performance metrics are faceted with the different models. Something to experiment with in the future.

Acknowledgements

This blog post was made possible thanks to:

References

[1]
R Core Team, R: A language and environment for statistical computing. Vienna, Austria: R Foundation for Statistical Computing, 2022 [Online]. Available: https://www.R-project.org/
[2]
Y. Xie, C. Dervieux, and A. Presmanes Hill, Blogdown: Create blogs and websites with r markdown. 2022 [Online]. Available: https://CRAN.R-project.org/package=blogdown

Disclaimer

The views, analysis and conclusions presented within this paper represent the author’s alone and not of any other person, organization or government entity. While I have made every reasonable effort to ensure that the information in this article was correct, it will nonetheless contain errors, inaccuracies and inconsistencies. It is a working paper subject to revision without notice as additional information becomes available. Any liability is disclaimed as to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause. The author(s) received no financial support for the research, authorship, and/or publication of this article.

Reproducibility

─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.1.3 (2022-03-10)
 os       macOS Big Sur/Monterey 10.16
 system   x86_64, darwin17.0
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/New_York
 date     2022-10-22
 pandoc   2.18 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/tools/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date (UTC) lib source
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 4.1.0)
 blogdown    * 1.13       2022-09-24 [1] CRAN (R 4.1.2)
 bookdown      0.29       2022-09-12 [1] CRAN (R 4.1.3)
 bslib         0.4.0.9000 2022-08-26 [1] Github (rstudio/bslib@fa2e03c)
 cachem        1.0.6      2021-08-19 [1] CRAN (R 4.1.0)
 callr         3.7.2      2022-08-22 [1] CRAN (R 4.1.2)
 cli           3.4.1      2022-09-23 [1] CRAN (R 4.1.2)
 codetools     0.2-18     2020-11-04 [1] CRAN (R 4.1.3)
 colorspace    2.0-3      2022-02-21 [1] CRAN (R 4.1.2)
 crayon        1.5.2      2022-09-29 [1] CRAN (R 4.1.3)
 DBI           1.1.3      2022-06-18 [1] CRAN (R 4.1.2)
 devtools    * 2.4.4      2022-07-20 [1] CRAN (R 4.1.2)
 digest        0.6.29     2021-12-01 [1] CRAN (R 4.1.0)
 dplyr         1.0.10     2022-09-01 [1] CRAN (R 4.1.2)
 ellipsis      0.3.2      2021-04-29 [1] CRAN (R 4.1.0)
 evaluate      0.16       2022-08-09 [1] CRAN (R 4.1.2)
 fansi         1.0.3      2022-03-24 [1] CRAN (R 4.1.2)
 fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.1.0)
 fs            1.5.2      2021-12-08 [1] CRAN (R 4.1.0)
 generics      0.1.3      2022-07-05 [1] CRAN (R 4.1.2)
 ggplot2     * 3.3.6      2022-05-03 [1] CRAN (R 4.1.2)
 ggthemes    * 4.2.4      2021-01-20 [1] CRAN (R 4.1.0)
 glue          1.6.2      2022-02-24 [1] CRAN (R 4.1.2)
 gtable        0.3.1      2022-09-01 [1] CRAN (R 4.1.2)
 htmltools     0.5.3      2022-07-18 [1] CRAN (R 4.1.2)
 htmlwidgets   1.5.4      2021-09-08 [1] CRAN (R 4.1.0)
 httpuv        1.6.6      2022-09-08 [1] CRAN (R 4.1.2)
 jquerylib     0.1.4      2021-04-26 [1] CRAN (R 4.1.0)
 jsonlite      1.8.0      2022-02-22 [1] CRAN (R 4.1.2)
 knitr         1.40       2022-08-24 [1] CRAN (R 4.1.3)
 later         1.3.0      2021-08-18 [1] CRAN (R 4.1.0)
 lifecycle     1.0.3      2022-10-07 [1] CRAN (R 4.1.2)
 magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.1.2)
 memoise       2.0.1      2021-11-26 [1] CRAN (R 4.1.0)
 mime          0.12       2021-09-28 [1] CRAN (R 4.1.0)
 miniUI        0.1.1.1    2018-05-18 [1] CRAN (R 4.1.0)
 munsell       0.5.0      2018-06-12 [1] CRAN (R 4.1.0)
 pillar        1.8.1      2022-08-19 [1] CRAN (R 4.1.2)
 pkgbuild      1.3.1      2021-12-20 [1] CRAN (R 4.1.0)
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.1.0)
 pkgload       1.3.0      2022-06-27 [1] CRAN (R 4.1.2)
 prettyunits   1.1.1      2020-01-24 [1] CRAN (R 4.1.0)
 processx      3.7.0      2022-07-07 [1] CRAN (R 4.1.2)
 profvis       0.3.7      2020-11-02 [1] CRAN (R 4.1.0)
 promises      1.2.0.1    2021-02-11 [1] CRAN (R 4.1.0)
 ps            1.7.1      2022-06-18 [1] CRAN (R 4.1.2)
 purrr         0.3.5      2022-10-06 [1] CRAN (R 4.1.2)
 R6            2.5.1      2021-08-19 [1] CRAN (R 4.1.0)
 Rcpp          1.0.9      2022-07-08 [1] CRAN (R 4.1.2)
 remotes       2.4.2      2021-11-30 [1] CRAN (R 4.1.0)
 rlang         1.0.6      2022-09-24 [1] CRAN (R 4.1.2)
 rmarkdown     2.16       2022-08-24 [1] CRAN (R 4.1.2)
 rstudioapi    0.14       2022-08-22 [1] CRAN (R 4.1.2)
 sass          0.4.2      2022-07-16 [1] CRAN (R 4.1.2)
 scales        1.2.1      2022-08-20 [1] CRAN (R 4.1.2)
 sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.1.0)
 shiny         1.7.2      2022-07-19 [1] CRAN (R 4.1.2)
 stringi       1.7.8      2022-07-11 [1] CRAN (R 4.1.2)
 stringr       1.4.1      2022-08-20 [1] CRAN (R 4.1.2)
 tibble        3.1.8      2022-07-22 [1] CRAN (R 4.1.2)
 tidyselect    1.2.0      2022-10-10 [1] CRAN (R 4.1.2)
 urlchecker    1.0.1      2021-11-30 [1] CRAN (R 4.1.0)
 usethis     * 2.1.6      2022-05-25 [1] CRAN (R 4.1.2)
 utf8          1.2.2      2021-07-24 [1] CRAN (R 4.1.0)
 vctrs         0.4.2      2022-09-29 [1] CRAN (R 4.1.3)
 withr         2.5.0      2022-03-03 [1] CRAN (R 4.1.0)
 xfun          0.33       2022-09-12 [1] CRAN (R 4.1.2)
 xtable        1.8-4      2019-04-21 [1] CRAN (R 4.1.0)
 yaml          2.3.5      2022-02-21 [1] CRAN (R 4.1.2)

 [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────