如何呈现具有确定行高的数据表?
How to render a dataTable with definite row height?
为了完成这样的任务,我已经苦苦挣扎了几个小时:
在 R Shiny 中,我需要显示一个 table,其中包含一列整数,其中 行之间的确定(相对较大)间距 。
renderTable()
函数中有spacing
参数,但即使将其设置为最大值'l'
仍然不足以满足我的目的。
我尝试使用 xtable 并考虑 Adjust row height xtable R 中的示例来做到这一点,但没有结果(我不知道 CSS)。
我在网上找到的最自然的方法是使用 DT
包和 Scroller
扩展,但下面的代码仍然没有结果
ui.R:
fluidPage(
sidebarLayout(
sidebarPanel(
dataTableOutput('dtable', width = '50%') # argument 'height' does not work here
),
mainPanel()
)
)
server.R:
library(shiny)
library(DT)
function(input, output) {
output$dtable <- DT::renderDataTable({
data.frame(SSD = c(2, 17, 19, 35))
},
extensions = 'Scroller',
options = list(
dom = 't',
ordering = FALSE,
scroller = list(rowHeight = 100)
)
)
}
它的输出只给出了列名(有什么问题??),但没有 Scroller
扩展,它显示预期的 table - 当然间距太小...
您想使用 rowCallback
选项并为每一行附加样式:
server.R
library(shiny)
library(DT)
function(input, output) {
output$dtable <- DT::renderDataTable({
data.frame(SSD = c(2, 17, 19, 35))
},
options = list(
dom = 't',
ordering = FALSE,
rowCallback = JS("function(r,d) {$(r).attr('height', '100px')}")
)
)
}
请注意,随着行数的增加,这可能会导致渲染时间增加
为了完成这样的任务,我已经苦苦挣扎了几个小时: 在 R Shiny 中,我需要显示一个 table,其中包含一列整数,其中 行之间的确定(相对较大)间距 。
renderTable()
函数中有spacing
参数,但即使将其设置为最大值'l'
仍然不足以满足我的目的。
我尝试使用 xtable 并考虑 Adjust row height xtable R 中的示例来做到这一点,但没有结果(我不知道 CSS)。
我在网上找到的最自然的方法是使用 DT
包和 Scroller
扩展,但下面的代码仍然没有结果
ui.R:
fluidPage(
sidebarLayout(
sidebarPanel(
dataTableOutput('dtable', width = '50%') # argument 'height' does not work here
),
mainPanel()
)
)
server.R:
library(shiny)
library(DT)
function(input, output) {
output$dtable <- DT::renderDataTable({
data.frame(SSD = c(2, 17, 19, 35))
},
extensions = 'Scroller',
options = list(
dom = 't',
ordering = FALSE,
scroller = list(rowHeight = 100)
)
)
}
它的输出只给出了列名(有什么问题??),但没有 Scroller
扩展,它显示预期的 table - 当然间距太小...
您想使用 rowCallback
选项并为每一行附加样式:
server.R
library(shiny)
library(DT)
function(input, output) {
output$dtable <- DT::renderDataTable({
data.frame(SSD = c(2, 17, 19, 35))
},
options = list(
dom = 't',
ordering = FALSE,
rowCallback = JS("function(r,d) {$(r).attr('height', '100px')}")
)
)
}
请注意,随着行数的增加,这可能会导致渲染时间增加