![](/img/trans.png)
[英]R shiny DT Package processing message and column header load avoidance
[英]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.