0

I would like to include a map in the README page of an R-Packages repository (vegtable), but I don't know, if it is really possible. For instance one example:

---
output:
  github_document:
    html_preview: false
---

```{r,echo=FALSE}
knitr::opts_chunk$set(
  collapse=TRUE,
  comment="#>",
  fig.path="man/figures/"
)
```

How to do a map:

```{r}
library(vegtable)
library(leaflet)

leaflet(Kenya_veg@header) %>%
    addTiles() %>%
    addCircleMarkers(lng = ~LONGITUDE, lat = ~LATITUDE, color = "red",
            opacity = 0.3, radius = 1)

```

There was a hint of including always_allow_html: true in the yaml head but it is not getting the desired behavior.

Miguel Alvarez
  • 314
  • 2
  • 11

1 Answers1

0

I think that is not possible. You can do


---
output: 
  md_document:
    variant: gfm
    preserve_yaml: true
---

And probably it would render with something like:


  <script type="application/json"data-for="7ab57412f7b1df4d5773">
    {"x":{"options":
      ...
      "jsHooks":[]}
  </script>


The problem is that Leaflet is a JavaScript library for use in html. For rendering it properly, the md file should be parsed as html (something that GH is not doing, the README is rendered as Markdown) and you would need to inject the leaflet js library on the GH page, that is something that I doubt you can do.

This post may give you some hints about how troublesome could be using leaflet on a markdown format:

https://dieghernan.github.io/201905_Leaflet_R_Jekyll/

dieghernan
  • 2,690
  • 8
  • 16