有没有办法在 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空格替换了。
我希望第二个单元格“新行”在单独的行上有“新”和“行”两个词。
这解决了这个问题:
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)