Have been trying to change the font size of all text in the tables generated by DT. However, I could only figure out how to change the size of the records using formatStyle(names(datCalc), fontSize = '12px')
. The column headers and buttons have text of the same size. Using R Markdown in RStudio.
一直在尝试更改DT生成的表中所有文本的字体大小。但是,我只能弄清楚如何使用formatStyle(names(datCalc),fontSize ='12px')更改记录的大小。列标题和按钮具有相同大小的文本。在RStudio中使用R Markdown。
2 个解决方案
#1
6
I think you almost got there. I solved it by explicitly telling DT::formatStyle()
which columns I wanted. I first tried using the names()
or colnames()
approach, as you did. For some reason this didn't work:
我想你差不多到了那儿。我通过明确地告诉DT :: formatStyle()我想要哪些列来解决它。我首先尝试使用names()或colnames()方法,就像你一样。出于某种原因,这不起作用:
iris %>%
DT::datatable() %>%
DT::formatStyle(columns = colnames(.), fontSize = '50%')
However, we know the iris
dataset has 5 columns, so I just did this:
但是,我们知道虹膜数据集有5列,所以我这样做了:
iris %>%
DT::datatable() %>%
DT::formatStyle(columns = c(1, 2, 3, 4, 5), fontSize = '50%')
In this case, I use font-size = 50%
, but you can also specify font-size = 12pt
as you did. You can also supply logical vectors like c(T, F, F, F, T)
to the columns
argument, and the formatting will apply to those columns for which you have stated TRUE
.
在这种情况下,我使用font-size = 50%,但你也可以像你一样指定font-size = 12pt。您还可以向columns参数提供c(T,F,F,F,T)等逻辑向量,格式将应用于您已声明为TRUE的列。
#2
1
Adding CSS through a javascript table header call seems to do the trick (i.e 'this.api().table().header()' ).
通过javascript表头调用添加CSS似乎可以解决问题(即'this.api()。table()。header()')。
datatable(..., options=list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'font-size': '50%'});",
"}")))
)
Citation: Section 4.3 @ https://rstudio.github.io/DT/options.html
引用:第4.3节@ https://rstudio.github.io/DT/options.html
#1
6
I think you almost got there. I solved it by explicitly telling DT::formatStyle()
which columns I wanted. I first tried using the names()
or colnames()
approach, as you did. For some reason this didn't work:
我想你差不多到了那儿。我通过明确地告诉DT :: formatStyle()我想要哪些列来解决它。我首先尝试使用names()或colnames()方法,就像你一样。出于某种原因,这不起作用:
iris %>%
DT::datatable() %>%
DT::formatStyle(columns = colnames(.), fontSize = '50%')
However, we know the iris
dataset has 5 columns, so I just did this:
但是,我们知道虹膜数据集有5列,所以我这样做了:
iris %>%
DT::datatable() %>%
DT::formatStyle(columns = c(1, 2, 3, 4, 5), fontSize = '50%')
In this case, I use font-size = 50%
, but you can also specify font-size = 12pt
as you did. You can also supply logical vectors like c(T, F, F, F, T)
to the columns
argument, and the formatting will apply to those columns for which you have stated TRUE
.
在这种情况下,我使用font-size = 50%,但你也可以像你一样指定font-size = 12pt。您还可以向columns参数提供c(T,F,F,F,T)等逻辑向量,格式将应用于您已声明为TRUE的列。
#2
1
Adding CSS through a javascript table header call seems to do the trick (i.e 'this.api().table().header()' ).
通过javascript表头调用添加CSS似乎可以解决问题(即'this.api()。table()。header()')。
datatable(..., options=list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'font-size': '50%'});",
"}")))
)
Citation: Section 4.3 @ https://rstudio.github.io/DT/options.html
引用:第4.3节@ https://rstudio.github.io/DT/options.html