DT, formatters and hidden columns

1,399 views
Skip to first unread message

Max Moro

unread,
Apr 28, 2015, 5:00:20 PM4/28/15
to shiny-...@googlegroups.com
On the DT package, I noticed when a column is hidden, the formatter formats the wrong column...

In this example the formatPercentage function is targeted to the 'cyl' column, but when there is  the visible=FALSE option, it picks the next column (disp)

datatable(mtcars
         ,options=list(columnDefs = list(list(visible=FALSE,targets=1)))
) %>% formatPercentage('cyl',1)

I don't know if this is an issue, but is there a way to avoid this behavior?
Thank you.
Max

adrie...@hotmail.com

unread,
Apr 29, 2015, 4:50:40 AM4/29/15
to shiny-...@googlegroups.com
You can write :

 datatable(mtcars
            ,options=list(columnDefs = list(list(visible=FALSE,targets=1)))
  ) %>% formatPercentage(1,1)

to target your first column.
Is that you want ?

Max Moro

unread,
Apr 29, 2015, 10:32:45 AM4/29/15
to shiny-...@googlegroups.com
I want to target the 'cyl' column that is the number 2. But if I write 

datatable(mtcars,options=list(columnDefs = list(list(visible=FALSE,targets=1)))) %>% formatPercentage(2,1)

the formatted column is 'disp' (number 3).

If I remove the visible=FALSE option, everything works fine

datatable(mtcars) %>% formatPercentage(2,1)


I think there is something to be fixed to consider the hidden columns on the formatters... 

Thanks for trying :)
Max

Yihui Xie

unread,
Apr 29, 2015, 1:39:02 PM4/29/15
to Max Moro, shiny-discuss
Thanks for the report. I'm not quite sure if there is a way to fix it,
and I'll try to find one. Column indices are tricky in two cases: 1)
with or without rownames; 2) with hidden columns. I explained the
first case in Section 2.3: http://rstudio.github.io/DT/ but personally
I really do not like it. It is annoying that one has to change the
column indices in different cases. A similar issue has been reported
to https://github.com/rstudio/DT/issues/51

Regards,
Yihui

Max Moro

unread,
May 1, 2015, 7:22:56 PM5/1/15
to shiny-...@googlegroups.com, massimil...@gmail.com
Thank you Yihui, 
Your reference is very helpful, I fit in the case number 2)... I'll work to find a workaround for my app.

Thanks

Yihui Xie

unread,
May 27, 2015, 7:07:47 PM5/27/15
to Max Moro, shiny-discuss
FYI, this problem has been fixed in the latest development version of
DT. Thanks again for the report.

Regards,
Yihui
> --
> You received this message because you are subscribed to the Google Groups
> "Shiny - Web Framework for R" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shiny-discus...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/shiny-discuss/7abbd545-5513-4977-b7b2-b3e3cb933921%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Max Moro

unread,
May 27, 2015, 7:43:58 PM5/27/15
to shiny-...@googlegroups.com, massimil...@gmail.com
Fantastic! Thank you Yihui!
Max
Reply all
Reply to author
Forward
0 new messages