DT 包 R Shiny 中的回车

eas*_*611 4 r shiny dt

有没有办法在 R 闪亮的应用程序中使用 DT 包显示回车?

我在这里尝试过代码:

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)
Run Code Online (Sandbox Code Playgroud)

\n符号不起作用,看起来该datatable函数用\n空格替换了。

我希望第二个单元格“新行”在单独的行上有“新”和“行”两个词。

eas*_*611 8

这解决了这个问题:

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)
Run Code Online (Sandbox Code Playgroud)