本文介绍了R闪亮设置DataTable列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试设置以Shiny呈现的DataTable中的列宽,并且无法使用aoColumnDefs选项实现它。有人尝试过吗?我的表格有1个文本,后跟3个数字列。数字列需要更窄,第一列(文本)应更宽。
I am trying to set the width of columns in a DataTable rendered in Shiny and am not able to implement it using the aoColumnDefs options. Has anyone tried this before ? My table has 1 text followed by 3 numeric columns. The numeric columns need to be narrower and the 1st column (text) wider.
output$result <- renderDataTable({
z <- as(dataInput(), "data.frame")
setnames(z, c("Rules", "Support", "Confidence", "StatDep"))
z
}, options = list(aLengthMenu = c(5, 30, 50), iDisplayLength = 5, bSortClasses = TRUE,
aoColumnDefs = list(sWidth = "50px", aTargets = list(1))))
谢谢,
- Raj。
**更新**这似乎可行,但可能还有其他选择,例如
** Update ** This seems to be working, but there might be other options to do this as well.
output$result <- renderDataTable({
z <- as(dataInput(), "data.frame")
setnames(z, c("Rules", "Support", "Confidence", "StatDep"))
z
}, options = list(aLengthMenu = c(5, 30, 50), iDisplayLength = 5, bSortClasses = TRUE,
bAutoWidth = FALSE,
aoColumn = list(list(sWidth = "150px", sWidth = "30px",
sWidth = "30px", sWidth = "30px"))
))
推荐答案
尝试一下
#OUTPUT - dtdata
output$table <- DT::renderDataTable({
data.frame(a=c(1,2,3,4,5),b=c("A","B","C","D","E"))
},
options = list(
autoWidth = TRUE,
columnDefs = list(list(width = '200px', targets = "_all"))
))
将所有列的宽度设置为200px。
Sets the width of all columns to 200px.
要设置选定列的宽度,请将目标
更改为数字或向量。
To set width of selected columns, change targets
to a number or vector.
targets = c(1,3)
这篇关于R闪亮设置DataTable列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!