4

I have created a flexdashboard that includes a map using the leaflet package.

I need to be able to select markers within a region of the map so that I can display summary statistics based upon those markers. leaflet-locationfilter appears to provide what I need, but I need to figure out how to include this in the generated HTML file. I have tried using "includes" in the flexdashboard header but this produces an error. Here is a simple test case:

---
title: "Dashboard Title"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    includes: includes(in_header = "TEST.HTML", before_body = "TEST.HTML", after_body = "TEST.HTML")
---

...where TEST.HTML is:

<!-- TEST TEST TEST -->

But this fails with:

output file: Dashboard.knit.md

Error in includes$in_header : $ operator is invalid for atomic vectors Calls: -> -> overlay -> pandoc_include_args Execution halted

I have had to resort to reading the code to figure out how to do this because it doesn't appear to be documented anywhere, but I've obviously missed something.

Any suggestions?

Michael Henry
  • 599
  • 2
  • 4
  • 17

1 Answers1

2

Instead of using R's built-in includes function like the documentation (pg. 4) oddly says to do, use YAML instead:

---
title: "Dashboard Title"
    output: 
    flexdashboard::flex_dashboard:
        orientation: columns
        vertical_layout: fill
        includes: 
            in_header: "TEST.HTML"
            before_body: "TEST.HTML"
            after_body: "TEST.HTML"
---

However, there is a different way of including leaflet plug-ins besides through flexdashboard. Use leaflet's own dependencies argument:

map$dependencies <- c(map$dependencies, list(htmlDependency(
    name = "Leaflet.locationfilter",
    version = "0.1",
    src = "PATH_TO_DIRECTORY",
    script = "locationfilter.js",
    stylesheet = "locationfilter.css"
)))
Youppi3
  • 66
  • 5