回车在DT包R闪亮

  • 本文关键字:闪亮 DT 回车 shiny dt
  • 更新时间 :
  • 英文 :


是否有一种方法可以在R闪亮的应用程序中使用DT包显示回车?

我试过这里的代码:

library(DT)
# create data frame with an example column
test_df <- data.frame(SAME =  "Same Line", NEW = "NewnLine")
# print data frame
datatable(test_df)

n符号不工作,看来datatable函数用空格代替了n

我想让第二个单元格"New Line"的单词"New"one_answers"Line"位于不同的行。

这就解决了问题:

library(DT)
# create data frame with an example column
test_df <- data.frame(SAME =  "Same Line", NEW = "NewnLine")
# 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)

这不是一个解决方案,而是@easports611评论的后续。下面是一个答案不工作的应用程序:

server <- function(input, output, session) {
  library(data.table)
  data("iris")
    output$buySegments <- DT::renderDataTable({
      colnames(iris)=c("a <br>b","c<br>d","e<br>f","g<br>h","i")
      sketch<-htmltools::withTags(table(
        tableHeader(iris
      )))
      #rangeRatio
      thing = DT::datatable(
        iris
        ,rownames = FALSE
        ,container = sketch
      )
      return(thing)
    }
    )  
}

ui=shinyUI(
  fluidPage(theme = "bootstrap.css",title = "Buyer Console",
            mainPanel(  
              DT::dataTableOutput('buySegments') 
            )
  )
)
shinyApp(ui = ui, server = server)

问题显然是我通过容器指定列名。事实证明,解决方案是在tableHeader函数中设置escape=F选项。

最新更新