Shiny renderTable split long lines at other characters

When using Shiny renderTable(), long lines inside each table cell are split for display at spaces and hyphens/dashes. Which other characters will it split at? Is it possible to use additional characters for splitting text?

If that's not possible, is it possible with DT::renderDT() perhaps?

it splits on whitespace which is a web standard.
you can use css to change the white-space behaviour; for example pre-line will honour your explicit linebreaks added in from \n

library(shiny)

phrase <- "This\n is a long text that might need to be split"

ui <- fluidPage(
  tags$style(
    "#t2 {white-space:pre-line;}"
  ),
  fluidRow(column(1,
                  tableOutput("t1"))),
  fluidRow(column(1,
                  tableOutput("t2")))

)

server <- function(input, output, session) {
  output$t1 <- renderTable(
    data.frame(x=phrase)
  )
  output$t2 <- renderTable(
    data.frame(x=phrase)
  )
}

shinyApp(ui, server)
1 Like