Rmarkdown html 报告中的 DT 数据表透明背景
DT datatable transparent background in Rmarkdown html reports
我的 html 输出 Rmarkdown 需要一个水印,但它被数据表掩盖了。
可能有一个简单的答案,但我还不知道 Javascript。有什么建议吗?
我试过使用 formatStyle 但它没有按预期工作:
datatable(mytable, escape = F, class = 'row-border hover compact') %>%
formatStyle(columns = names(mytable), backgroundColor = "#FFFFFF00")
我的水印是 style.css:
.watermark {
opacity: 0.2;
position: fixed;
top: 50%;
left: 50%;
font-size: 600%;
color: #00407d;
}
和完整的 Rmarkdown 示例:
---
title: "Untitled"
output:
html_document:
highlight: pygments
theme: "flatly" # for: html_document black theme: darkly, white them: flatly
toc: TRUE
toc_float: TRUE # for: html_document
css: test-styles.css
---
<div class="watermark">DRAFT</div>
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(DT)
```
## Tables
```{r iris}
DT::datatable(iris, class = '') %>%
DT::formatStyle(columns = "Species", backgroundColor = "#00000000") %>%
DT::formatStyle(columns = "Petal.Width", backgroundColor = "#FFFFFFFFF")
DT::datatable(iris, class = '', options = list(
initComplete = JS("
function(settings, json) {
$(this.api().table().body()).css({
'background-color': 'rgba(255,0,0,0.2)',
'color': 'rgba(0,255,0,0.8)'
});
}")))
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
给你的 watermark
添加一个大 z-index
class:
.watermark {
opacity: 0.2;
position: fixed;
top: 50%;
left: 50%;
font-size: 600%;
color: #00407d;
z-index: 1000000;
}
那就直接datatable(iris)
,不用设置背景色
我的 html 输出 Rmarkdown 需要一个水印,但它被数据表掩盖了。
可能有一个简单的答案,但我还不知道 Javascript。有什么建议吗?
我试过使用 formatStyle 但它没有按预期工作:
datatable(mytable, escape = F, class = 'row-border hover compact') %>%
formatStyle(columns = names(mytable), backgroundColor = "#FFFFFF00")
我的水印是 style.css:
.watermark {
opacity: 0.2;
position: fixed;
top: 50%;
left: 50%;
font-size: 600%;
color: #00407d;
}
和完整的 Rmarkdown 示例:
---
title: "Untitled"
output:
html_document:
highlight: pygments
theme: "flatly" # for: html_document black theme: darkly, white them: flatly
toc: TRUE
toc_float: TRUE # for: html_document
css: test-styles.css
---
<div class="watermark">DRAFT</div>
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(DT)
```
## Tables
```{r iris}
DT::datatable(iris, class = '') %>%
DT::formatStyle(columns = "Species", backgroundColor = "#00000000") %>%
DT::formatStyle(columns = "Petal.Width", backgroundColor = "#FFFFFFFFF")
DT::datatable(iris, class = '', options = list(
initComplete = JS("
function(settings, json) {
$(this.api().table().body()).css({
'background-color': 'rgba(255,0,0,0.2)',
'color': 'rgba(0,255,0,0.8)'
});
}")))
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
给你的 watermark
添加一个大 z-index
class:
.watermark {
opacity: 0.2;
position: fixed;
top: 50%;
left: 50%;
font-size: 600%;
color: #00407d;
z-index: 1000000;
}
那就直接datatable(iris)
,不用设置背景色