The R markdown package no longer supports htmlwidgets, and is no longer supported itself. It suggests that litedown has superseded it.
Added to clarify: The markdown package is not the same as the rmarkdown package. I think markdown came first, but that's not important. Until recently it was still supported as a lightweight alternative to rmarkdown, which requires Pandoc and a lot of R packages. Prior to version 2.0 of markdown (which was released last month) it supported htmlwidgets. Now it doesn't.
Has anyone worked out the details of supporting htmlwidgets in litedown?
For example, this document doesn't display anything:
---
title: "leaflet in litedown"
output: html
knit: litedown:::knit
---
```{r}
library(leaflet)
leaflet() %>%
addTiles() %>%
setView(lng = -3.7, lat = 40.4, zoom = 5)
```
This one (using the full rmarkdown, and requiring Pandoc) is fine:
---
title: "leaflet in rmarkdown"
output: html_document
---
```{r}
library(leaflet)
leaflet() %>%
addTiles() %>%
setView(lng = -3.7, lat = 40.4, zoom = 5)
```
What do I need to add to the litedown document to get the map to display?
It's not possible by only using leaflet syntax from R, see the HTML Widgets chapter within the documentation (in particular 6.1 The dilemma and 6.4 Leaflet for an example).
Your example could be translated to this (similar to the 6.4 example):
---
title: "leaflet in litedown"
---
```{r}
litedown::vest(css = '@npm/leaflet/dist/leaflet', js = '@npm/leaflet')
```
```{r}
loc = c(40.4, -3.7)
zoom = 5
```
Provide a fenced Div with the ID `unmc` as the map container, and create the map:
::: {#unmc style="height: 500px;"}
:::
```{js, type = 'module', fill = xfun::tojson}
const map = L.map('unmc').setView(`{ loc }`, `{ zoom }`);
// add a tile layer
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 5,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
```
It would look like this:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With