【发布时间】:2020-02-05 13:48:19
【问题描述】:
我有两个列/行数相同的 DT 表。我想在 R Viewer 中显示它们。我尝试使用 print 但它只是创建了两个不同的视图。
我尝试使用 htmlTools 包中的可浏览,我认为它工作正常。但是,它使两个表格重叠,右侧的滚动条也与表格重叠。只是想知道是否有办法设置表格边距?我尝试添加到样式选项中,但它不起作用。任何帮助将不胜感激!
library(DT)
library(htmltools)
t1<-data.frame(matrix(data = round(rnorm(285), 3), nrow=15, ncol=19,
dimnames = list(NULL,seq(from=0, to=0.9, by=0.05))), check.names=FALSE)
t2<-data.frame(matrix(data = round(rnorm(285), 3), nrow=15, ncol=19,
dimnames = list(NULL,seq(from=0, to=0.9, by=0.05))), check.names=FALSE)
dt_t1 <- datatable(t1,
caption = paste0("Variable tested: "),
rownames=TRUE,
fillContainer = F,
options =list(pageLength = 20,
dom = "t",
ordering = F,
autoWidth = TRUE,
initComplete = htmlwidgets::JS(
"function(settings, json) {",
paste0("$(this.api().table().container()).css({'font-size': '", "9pt", "'});"),
"}"),
columnDefs = list(list(width = '30px', targets = 0), list(width = '10px', targets = c(1,2)))
)
)
dt_t2 <- datatable(t1,
caption = paste0("Variable tested: "),
rownames=TRUE,
fillContainer = F,
options =list(pageLength = 20,
dom = "t",
ordering = F,
autoWidth = TRUE,
initComplete = htmlwidgets::JS(
"function(settings, json) {",
paste0("$(this.api().table().container()).css({'font-size': '", "9pt", "'});"),
"}"),
columnDefs = list(list(width = '30px', targets = 0), list(width = '10px', targets = c(1,2)))
))
browsable(
tagList(list(
tags$div(
style = 'display:block; float:top; margin-right:30px;',
dt_t1
),
tags$div(
style = 'display:block;float:top; margin-right:30px; margin-top:0px;',
dt_t2))))
【问题讨论】: