如何使用 kableExtra 只添加一个超链接

How to add only one hyperlink using kableExtra

我已经阅读了这样的教程:[kable kableExtra,带有超链接的单元格][1]

但是完全看不懂

我的第一个问题:

我只想添加一个超链接而不更改其名称。

我能做的是这样的:

dt%>%kable(caption = "Sample information") %>%
  kable_styling(bootstrap_options = c("striped"),full_width = F,html_font = "helvetica") %>%
  column_spec(1, bold = T, border_right = F,width = "8cm") %>%
  column_spec(2, width = "16cm")%>%
  save_kable(file = "table1.html", self_contained = T)

这是我的示例数据:

dt<-structure(list(GSE95401_EAE_Acute = c("Profiling the mouse brain endothelial transcriptome in health and disease models reveals a core blood-brain barrier dysfunction module", 
"31611708", "https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE95401", 
"EAE was induced by injecting the MOG35–55 peptide containing emulsion.", 
"Mus musculus", "C57BL/6-Rosa-tdTomato", "2-3 months", "Spinal Cord", 
"fluorescence-activated cell sorting (FACS)", "EAE Acute(Acute timepoints were taken on the first day that mice displayed a loss of 1 gram body weight.)", 
"3", "EAE control", "3")), row.names = c("Original publication title", 
"PMID", "Data source", "Disease/Treatment", "Species", "Strain", 
"Age", "Organ", "EC isolation method", "Treated group information", 
"Treated group replication no.", "Control group information", 
"Control group replication no."), class = "data.frame")

我的第二个问题是:

如何使我的数据中的“示例信息”的粗体和字体大小发生变化?

我只想在我的数据中添加一个名为 "https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE95401" 的超链接,但是不是多个链接

我的意思是有人可以点击它并打开一个新网站。

我使用 cell_spec() 和 text_spec() 使用了 R 包 KableExtra,但它不起作用。

希望有人能帮助我?

日期:2021年03月08日15:06:44。 我找到了正确的方法:

dt[3,1]<-text_spec("https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE95401", 
                   link = "https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE95401",color = "black",bold = T)
caption<-text_spec("Sample information",bold = T,font_size = 30,color = "black")
dt%>%kable(caption = caption,escape = FALSE) %>%
  kable_styling(bootstrap_options = c("striped","hover","condensed"),full_width = F,html_font = 4) %>%
  column_spec(1, bold = T, border_right = F,width = "8cm") %>%
  column_spec(2, width = "16cm")%>%
  save_kable(file = "table2.html", self_contained = T)

效果很好。

由于您想要的最终输出是一个 HTML 文件,您可以使用 HTML 代码来实现您想要的。

library(kableExtra)
dt%>%
  kable(caption = "<a href = 'https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE95401'><b style = 'font-size : 28'>Sample information</b></a>") %>%
  kable_styling(bootstrap_options = c("striped"),full_width = F,html_font = "helvetica") %>%
  column_spec(1, bold = T, border_right = F,width = "8cm") %>%
  column_spec(2, width = "16cm") %>%
  save_kable(file = "table1.html", self_contained = T)