简体   繁体   English

突出显示带有条件逻辑的单元格(对于html,R Markdown输出)

[英]Highlight a cell with conditional logic (for html, R Markdown output)

I want to highlight certain cells in a table. 我想突出显示表格中的某些单元格。

For example, highlight all cells where total_n_obs > 5000 . 例如,突出显示total_n_obs > 5000所有单元格。

Image 图片

I have seen solutions from ~2 years ago (which use CSS or pander) but have not been able to implement them. 我看到了大约2年前的解决方案(使用CSS或pander),但无法实现它们。

Is there a way to code this directly into an RMarkdown script? 有没有一种方法可以直接将此代码编码到RMarkdown脚本中?

Thanks a lot, I really appreciate any help/ideas! 非常感谢,非常感谢您的帮助/想法!

To highlight text change the background-color style of total_n_obs column, as shown in the example below. 要突出显示文本,请更改total_n_obs列的背景颜色样式,如下例所示。 (I have created a new column using the plyr::summarise command) (我使用plyr :: summarise命令创建了一个新列)

library(plyr)

df2 <- adply(df,1,
summarise, total_n_obs_t = ifelse(total_n_obs >= 5000,
paste('<div style="background-color: yellow; text-align: right;">',total_n_obs,'</div>',sep=""),
          paste('<div style="font-weight: bold; text-align: right;">',total_n_obs,'</div>',sep="")
                                 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM