Q: Create text wrap and manage column width with Datatable in Shiny I have a data table that has a lot of written text. I would like to organize this in an easy to read way. I have tried a few ideas but they do not seem to work. I am also open to any advice on how I should be organizing the data table.
Here is my code I am trying to control the width of the columns. Right now the width are extremely wide and i would like to narrow selected columns quite a bit.
output$newsfeed = renderDataTable({
  datatable(df, rownames = F, extensions = "Scroller", 
          options = list(deferRender = TRUE,
                         scrollY = 400,
                         scrollX = TRUE,
                         scroller = TRUE,
                         autoWidth = TRUE,
                         columnDefs = list(list(width = '50px', targets = list(1,2,3,4,5)))
                                                                       
  ))
})


Thank you for your help.

A: Try using width = '10%' for the columns of interest.
library(DT)
library(shiny)

dat <- data.frame(
  V1 = c("A", "B"),
  V2 = c(
    "A cool guy living in US and Canada", 
    "A cool guy living in New York"
  ),
  V3 = c(
    "A cool guy living in US and Canada", 
    "A cool guy living in New Jersey"
  ),
  V4 = c(
    "A cool guy living in US and Canada", 
    "A cool guy living in California"
  ),
  V5 = c(
    "A cool guy living in the US and else where", 
    "A cool guy living in Texas"
  ),
  stringsAsFactors = FALSE
)

ui <- fluidPage(
  DTOutput("table")
)

server <- function(input, output){
  
  output[["table"]] <- renderDT({
    datatable(dat, options = list(
      deferRender = TRUE,
      scrollY = 400,
      scrollX = TRUE,
      scroller = TRUE,
      autoWidth = TRUE,
      columnDefs = list(list(width = '10%', targets = c(2,3,4)))
    ))  # %>% formatStyle(columns = c(2,3), width='20px')
  })
}

shinyApp(ui, server)



A: I guess 'extensions = "Scroller"' conflicts controlling column width.
When I add 'extensions = "Scroller"' to YBS's code then texts is not wrapped.
