2016-08-16 63 views
2

我創建了一個包含使用傳單包的地圖的flexdashboard。如何在FlexDashboard中包含javascript和css?

我需要能夠在地圖上的一個區域內,選擇標記,這樣我可以顯示基於這些指標彙總統計。 leaflet-locationfilter似乎提供我所需要的,但我需要弄清楚如何將這包括在生成的HTML文件中。我曾嘗試在flexdashboard標題中使用「includes」,但這會產生錯誤。下面是一個簡單的測試案例:

--- 
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") 
--- 

...這裏的test.html是:

<!-- TEST TEST TEST --> 

但這種失敗:

輸出文件:Dashboard.knit.md

錯誤包括$ in_header:$操作是 呼叫原子向量無效: - > - >覆蓋 - > pandoc_include_args 執行暫停

我不得不求助於閱讀the code弄清楚如何做到這一點,因爲它似乎並沒有被記錄任何地方,但我顯然錯過了一些東西。

有什麼建議嗎? (。第4頁)

回答

1

相反,使用R內置的像documentationincludes功能奇怪的說做的,用YAML來代替:

--- 
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" 
--- 

然而,包括單張插件的方式不同除了通過flexdashboard。使用單張自己dependencies說法:

map$dependencies <- c(map$dependencies, list(htmlDependency(
    name = "Leaflet.locationfilter", 
    version = "0.1", 
    src = "PATH_TO_DIRECTORY", 
    script = "locationfilter.js", 
    stylesheet = "locationfilter.css" 
))) 
相關問題