2017-02-21 5 views
5

문제가 https://github.com/rstudio/rmarkdown/issues/967으로보고되었습니다.이 문제를 해결할 수있는 방법이 있습니까?Rmarkdown overlapping output

enter image description here

아래

재현 예 (효과를 볼 수 n 및 nGroup 변화 - 아니 중복 N = 100 nGroup = 10) :

--- 
title: "Test links to sections in DT" 
output: html_document 
--- 

```{r setup, include=FALSE} 
knitr::opts_chunk$set(echo=FALSE) 
knitr::opts_chunk$set(message=FALSE) 
knitr::opts_chunk$set(warning=FALSE) 

## DT Test 

```{r echo=FALSE} 
library(DT) 

n <- 1000 
nGroup <- 100 

testDF <- data.frame(text=paste0("Section", 1:n), 
        number=1:n, 
        group=rep(1:(n/nGroup), n/nGroup)) 

datatable(head(testDF), caption="Whole table", rownames=FALSE, escape=FALSE, options=list(paging=FALSE, info=FALSE)) 

getDT<-function(x) { 
    a <- list() 
    a[[1]] <- htmltools::tags$h3("test1") 
    a[[2]] <- datatable(x[, c("text", "number")], caption=htmltools::tags$caption(style="caption-side: top; text-align: left;", "Group: ", htmltools::strong(x$group)), rownames=FALSE, escape=FALSE, filter=c("none"), options=list(paging=FALSE, info=FALSE)) 
    a[[3]] <- htmltools::tags$h4("test1") 

    return(a) 
} 

res <- lapply(split(testDF, testDF$group), getDT) 

htmltools::tagList(res) 
``` 

답변

5

를 귀하의 예제가 생성하는 HTML을 보면, I

<div class="datatables html-widget html-widget-static-bound" 
    id="htmlwidget-3efe8ca4aa087193f03e" 
    style="width:960px;height:500px;"> 

주 500 픽셀로 높이를 설정하는 인라인 스타일 : 같이 div 태그의 무리를 참조하십시오. 그러나 div의 콘텐츠는 500 픽셀보다 훨씬 크기 때문에 div의 경계를 넘었습니다.

500px이 어디서 왔는지 모르겠지만 해결 방법으로 다른 스타일로 무시할 수 있습니다. 예를 들면, (헤더 이후) 당신의 RMarkdown의 상단이 추가

<style type="text/css"> 
    div.datatables { height: auto !important;} 
</style> 

또는, 당신은 CSS로 정리하여 RMarkdown을 유지하고 싶은 경우, 별도의

div.datatables { 
    height: auto !important; 
} 

를 넣어 CSS 파일을 만들고 다음과 같이 RMarkdown 헤더에 링크하십시오.

--- 
title: "Test links to sections in DT" 
output: 
    html_document: 
    css: overlap_workaround.css 
---