[R] Just a Demo: Blogdown Madness with htmlwidgets
Abstract / TL;DR
Demo Site. Just testing the embedding of HTML widgets (Leaflet, Xarigan Slides, DT::datatable(), Shiny App) in R Blogdown posts.
library(tidyverse)
# library(sf)
1 Leaflet
dc_crime <- sf::st_read("https://opendata.arcgis.com/datasets/dc3289eab3d2400ea49c154863312434_8.geojson", quiet = TRUE)
library(leaflet)
leaflet() %>%
addTiles() %>%
addCircles(data = dc_crime, color = "#800000")
# library(leaflet.extras)
leaflet() %>%
addTiles() %>%
setView(13.37, 52.525, zoom = 17)
2 Xarigan Slides
# need to find a solution for local embedding. here::here() does not produce a URL
knitr::include_url("https://dadascience.design/talks/rblogdown/rblogdown.html")
3 DT::datatable()
does not work on mobile screens, yet
There are two ways. The quick & dirty way is to use the x
package, which will give us the widget as an iframe
:
# install.packages('widgetframe')
library(widgetframe)
## Lade nötiges Paket: htmlwidgets
DT::datatable(
elementId = "datatableWidget",
head(mtcars, 10),
fillContainer = FALSE, options = list(pageLength = 8)) %>%
frameWidget(width = "100%", height = "100%", options = )
the robust way (to be tested yet): https://stackoverflow.com/questions/43594039/dt-package-not-working-with-blogdown-using-hugo-future-imperfect-theme
4 Shiny App
knitr::include_app("https://yihui.shinyapps.io/miniUI/",
height = "600px")
5 Conclusion
Proof-of-concept proven, I guess.