Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to right align columns of DataTable in R Shiny?

Tags:

jquery

r

dt

shiny

From this post I gather we should define an alignRight CSS class with the desired alignment:

# ui.R
sidebarLayout(...,
    mainPanel(
        tags$head(
            tags$style(".alignRight { align: right; }", media = "all", type = "text/css")
        ),
        ...     # content with call to dataTableOutput("myTable")
    )
)

and then when creating the DataTable, use the aoColumnDefs option to set class of the desired columns to alignRight:

# server.R
shinyServer(
    function(input, output) {...
        output$myTable <- renderDataTable(...,
            options = list(
                aoColumnDefs = '[{"aTargets": [7, 9, 10], "sClass": "alignRight"}]'
            )
        )
    }
)

However, this has had no effect on my DataTable, when remains left aligned for all columns. I thought a simple alignment issue would be easy to sort out, but after many hours, apparently not so. Any ideas would be much appreciated.

like image 533
mchen Avatar asked Oct 14 '25 14:10

mchen


1 Answers

The following works fine with no custom class definition:

option=list(columnDefs=list(list(targets=3:5, class="dt-right")))
like image 113
dk. Avatar answered Oct 17 '25 04:10

dk.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!