我试图在Shiny中呈现的DataTable中设置列的宽度,并且无法使用aoColumnDefs选项实现它.有人曾尝试过这个吗?我的表有1个文本,后跟3个数字列.数字列需要更窄,第1列(文本)更宽.
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))))
Run Code Online (Sandbox Code Playgroud)
谢谢,
**更新**这似乎有效,但也可能有其他选择.
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", …Run Code Online (Sandbox Code Playgroud) 有没有办法设置数据表选项来减少列填充?此链接建议autoWidth=TRUE与 with 一起使用scrollX=TRUE,但在我的代码中不起作用。
正如您在下图中所看到的,列之间有很大的差距,迫使用户滚动,如果可能,我希望避免这种情况。这个链接和这个链接在java中有同样的问题
这是呈现数据表的代码。
output$book_table <- DT::renderDT(RVTables$book %>%
filter(deal==as.numeric(input$deal_choice)),
selection = list(mode="single",selected=row_edited),
editable = TRUE,
rownames = FALSE,
options=list(
autoWidth=TRUE,
scrollX = TRUE,
ordering=FALSE,
pageLength=12,
scrollY = TRUE,
bLengthChange= FALSE,
searching=FALSE
)
)
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。