Vinod P
Vinod P

Reputation: 99

Split the line into 2 in DT table

from the below dataset, can we split the line in Cola into 2 lines as shown in expected output? The same line but splitted into 2 lines?

library(shiny)
library(DT)
 
ui <- fluidPage(
  DTOutput("example_table")
)
 
server <- function(input, output, session) {
 
  new_data <- data.frame(cola = c("fsdfdsgfsdgfdgfdgfdgdhgdgdfgdfgsfsgsfgsfdgfdgdfgfdgsfgfgfdgdd","fsgfdgfdgdfsdfgdfgdhdfgsdfsdfgfgdhdhfghfghfghsdfs"), b=c(1,2))
 
  output$example_table <- DT::renderDT({
    datatable(new_data,escape = FALSE)
  })
}
 
shinyApp(ui, server)

Expected output

enter image description here

Upvotes: 0

Views: 678

Answers (1)

ismirsehregal
ismirsehregal

Reputation: 33417

You can simply insert <br> at the point you want the line break.

library(shiny)
library(DT)

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

server <- function(input, output, session) {
  
  new_data <- data.frame(cola = c("fsdfdsgfsdgfdgfdgfdgdhgdgd<br>fgdfgsfsgsfgsfdgfdgdfgfdgsfgfgfdgdd","fsgfdgfdgdfsdfgdfgdhdfgsdf<br>sdfgfgdhdhfghfghfghsdfs"), b=c(1,2))
  
  output$example_table <- DT::renderDT({
    datatable(new_data,escape = FALSE)
  })
}

shinyApp(ui, server)

result

Upvotes: 3

Related Questions