R Shiny set DataTable column width

不问归期 提交于 2019-11-27 04:21:34

Try this

#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"))
))

Sets the width of all columns to 200px.

To set width of selected columns, change targetsto a number or vector.

targets = c(1,3)

By the way, in case you're like me and never used DataTables before version 1.10 came out -- The examples above confused me at first, because they use the notation that was used in version 1.9 but 1.10 introduces new notation: http://datatables.net/upgrade/1.10-convert

I've been using the new syntax, i.e.,

columnDefs instead of aoColumnDefs http://datatables.net/reference/option/columnDefs

width instead of sWidth http://datatables.net/reference/option/columns.width etc.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!