Controlling column width in renderDataTable output

3,718 views
Skip to first unread message

Kevin Ushey

unread,
Jan 31, 2014, 5:23:16 PM1/31/14
to shiny-...@googlegroups.com
Hi,

Is there an easy way to control, at the R level, the width of each column generated in the DataTable?

The DataTables documentation suggests this could be passed through in the 'aoColumnDefs' option, but I am not sure exactly how I would specify this in the 'shiny::renderDataTable' options argument. (See: http://datatables.net/usage/columns).

Thanks!
-Kevin

y.le...@gmail.com

unread,
Feb 1, 2014, 12:10:28 PM2/1/14
to shiny-...@googlegroups.com
Hi,

This is an example:

output$mytable <- renderDataTable({
if (nrow(subset(outputT8()))==0) invisible()
else subset(outputT8(),select=c(3,1,2,5,4,6,11))
},option=list(iDisplayLength=15,bSortClasses = TRUE,bAutoWidth=FALSE,
aoColumnDefs = list(list(sWidth=c("100px"), aTargets=c(list(0),list(1),list(2),list(3),list(4),list(5)))))
)

hope it helps

Kevin Ushey

unread,
Feb 3, 2014, 7:16:28 PM2/3/14
to shiny-...@googlegroups.com
Perfect. Thanks for your help!

Stéphane Laurent

unread,
Feb 4, 2014, 4:13:14 AM2/4/14
to shiny-...@googlegroups.com
Hi, 
For me this works well:
aoColumnDefs = list(list(sWidth=c("100px"), aTargets=list(0)))

But for more than one column the width does not change when I do:
aoColumnDefs = list(list(sWidth=c("100px"), aTargets=c(list(0),list(1))))

Yann Le Strat

unread,
Feb 4, 2014, 6:32:59 AM2/4/14
to shiny-...@googlegroups.com
I'm not sure but I believe that there is no change when you specify the width of all the columns
There is a change if you specify 1 or 2 or n-1 width values if your table has n columns, as in my example.
I don't know if there is another solution.
Reply all
Reply to author
Forward
0 new messages