Is there a way to display carriage returns using the DT package in an R shiny app?
I have tried the code here:
library(DT)
# create data frame with an example column
test_df <- data.frame(SAME = "Same Line", NEW = "New\nLine")
# print data frame
datatable(test_df)
The \n
notation does not work, and it appears the datatable
function replaces the \n
with a space.
I want the second cell "New Line" to have the words "New" and "Line" on separate lines.
This solves the issue:
library(DT)
# create data frame with an example column
test_df <- data.frame(SAME = "Same Line", NEW = "New\nLine")
# replace \n with <br/>
test_df$NEW <- gsub(pattern = "\n", replacement = "<br/>", x = test_df$NEW)
# print data frame
# with escape set to FALSE
datatable(test_df, escape = FALSE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With