繁体   English   中英

DT包装R Shiny中的回车

[英]Carriage returns in DT package R Shiny

有没有办法在R Shiny应用程序中使用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)

\\n表示法不起作用,并且看来datatable函数将\\n替换为空格。

我希望第二个单元格“ New Line”在单独的行上包含单词“ New”和“ Line”。

这样可以解决问题:

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)

这不是解决方案,而是@ 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选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM