2017-11-15 12 views
0

r chunk을 사용하여 내 Rmd에 css 파일을 추가하고 싶습니다. 그러나 예를html_document - css 파일의 출력 내에 r 청크 추가

--- 
title: "Untitled" 
output: 
    html_document: 
     css: '`r system.file("shinydashboard.css" , package = "shinydashboard")`' 
--- 

를 들어 내가 오류가있어 : 나는 모두와 관련된 질문 (thisthis)를 읽을

pandoc: Could not fetch `r system.file(
`r system.file(: openBinaryFile: does not exist (No such file or directory) 
Error: pandoc document conversion failed with error 67 
Execution halted 

,하지만 r chunkhtml_document 출력에 발생하는 경우가 상황을 커버하지 않았다 (Ramnathv이 brew 패키지를 언급하지만, 나는 '14 년에 게시 된 것 외에 그것을 테스트하지 않았다.).

RStudio에서 Knit 단추를 사용하는 것이 가능하면 좋을 것입니다.

감사합니다,

업데이트

내가 html_documentr chunk를 사용하여 하나의 디렉토리에서 모든 .CSS 파일을 포함 할 때 또 한가지입니다. 여기에 내가 www 디렉토리에서 모든 파일을 포함 할 :

--- 
title: "Untitled" 
output: 
    html_document: 
     css: "`r x <- list.files(path = 'www', pattern = '*.css', full.names = T); x <- paste(x, collapse = '\', \'');z <- paste0('[ \'', paste0(x, collapse = ', '), '\' ]'); z`" 
--- 
+1

'setup'R 청크에서'htmltools :: includeCSS (system.file ("shinydashboard.css", package = "shinydashboard")))'를 사용하면 작동하지 않습니까? –

+0

작동하지 않습니다. 게다가'before_body'에 추가하고 싶은 html 파일이 있다면? – Nicolabo

답변

2

(하단에 참고 사항을 참조하십시오) !expr을 사용하여 포맷해야 YAML 헤더의 식입니다.

--- 
title: "Untitled" 
output: 
    html_document: 
    css: !expr system.file("shinydashboard.css" , package = "shinydashboard") 
--- 


## Header 

```{r meta} 
rmarkdown::metadata 
``` 

이것은 당신이 명확하게 제대로로드 CSS를 볼 수있는 다음과 같은 출력을 생성합니다. 렌더링하는 동안 무슨 일이 일어나고 있는지 이해하기

enter image description here

, pandoc 명령이 실행되고 보는 것이 중요합니다. 다중 파일 업데이트의 경우 정적동적을 비교할 수 있습니다.

--- 
title: "Untitled" 
output: 
    html_document: 
    css: [ 'www/file1.css', 'www/file2.css' ] 
--- 

# /usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS so.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output so.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template /usr/share/R/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --css www/file1.css --css www/file2.css --variable 'theme:bootstrap' --include-in-header /tmp/RtmpRdKgYW/rmarkdown-str3eef4edabf99.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'  

중요한 것은, 당신은 --css www/file1.css --css www/file2.css을 볼 수, 파일은 파일을 포함 모두 CSS 제대로 렌더링합니다.

--- 
title: "Untitled" 
output: 
    html_document: 
    css: !expr x <- list.files(path = "www", pattern = "*.css", full.names = T); x <- paste(x, collapse = "\', \'"); z <- paste0("[ \'", paste0(x, collapse = ", "), "\' ]"); z 
--- 

# /usr/lib/rstudio-server/bin/pandoc/pandoc +RTS -K512m -RTS so.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output so.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template /usr/share/R/library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --css "[ 'www/file1.css', 'www/file2.css' ]" --variable "theme:bootstrap" --include-in-header /tmp/RtmpMStG00/rmarkdown-str423c7a02dab7.html --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" 

여기서 불행히도 --css "[ 'www/file1.css', 'www/file2.css' ]"을 찾습니다. 나는 cat, capture.output, as.namenoquote 행운을 포함한 몇 가지 트릭을 시도했다. 이 양식을 pandoc으로 제출하려면 으로 개선해야 할 수 있습니다.

N.B. It is worth noting this is indeed a duplicate of this question where the answer by Eli Holmes demonstrates the alternate syntax. He also notes a change in the development version, which may include the css field.