I am attempting to achieve the following with my datatable:
- Ensure all columns are uniform width
- Left-align both the header and content of the datatable
- Enable horizontal scrolling when it reaches the mainPanel width
However, I'm facing issues where the datatable is automatically centered within the mainPanel and the alignment of the header and content is off.
For example:
library(shiny)
library(dplyr)
library(DT)
ui <- fluidPage(
titlePanel("Test Example"),
mainPanel(
width = 10,
dataTableOutput("cars.table")
)
)
server <- function(input, output) {
output$cars.table <- renderDataTable({
t(cars[1:10, ]) %>%
datatable(class = "compact small",
options = list(columnDefs = list(list(width = "25px", targets = "_all")), scrollX = TRUE, autoWidth = TRUE,
paging = FALSE, ordering = FALSE, searching = FALSE))
})
}
shinyApp(ui = ui, server = server)
Update 2019/05/03:
It seems that this question suggests that the issue could be due to autoWidth = TRUE
. However, there isn't a solution provided in the question. It appears we can't remove autoWidth = TRUE
if we need to adjust column width as well.