【问题标题】:Rendering datatable in Shiny在 Shiny 中渲染数据表
【发布时间】:2018-05-09 12:36:33
【问题描述】:

我有这张表,其中包含一些带有大量文本的字段,例如摘要,当我渲染它们时,它看起来很糟糕。

有没有办法只显示部分文本,带有“...”?

喜欢:

id;name;author;abstract
123;Lucca;Adam;"Abstract text..."

这是它的外观图片:

数据表:

【问题讨论】:

标签: r shiny


【解决方案1】:

正如cmets中提到的,基于Shiny renderDataTable | how to limit text size displayed,你可以实现它:

# generating new variable in iris dataset with 5000 characters per row
iris$text <- apply(iris, 1, function(x) {paste0(letters[sample(26,5000,T)],collapse = "")})
# increasing the volume of data to 15K rows
iris <- do.call("rbind", replicate(100, iris, simplify = FALSE))

# Shiny app example
library(shiny)
library(DT)

shinyApp(
  ui = fluidPage(
    fluidRow(
      column(12,
             dataTableOutput('table')
      )
    )
  ),
  server = function(input, output) {
    output$table <- renderDataTable(iris,
                                    options = list(columnDefs = list(list(
                                      targets = 6,
                                      render = JS(
                                        "function(data, type, row, meta) {",
                                        "return type === 'display' && data.length > 6 ?",
                                        "'<span title=\"' + data + '\">' + data.substr(0, 6) + '...</span>' : data;",
                                        "}")
                                    ))), callback = JS('table.page(3).draw(false);'))
  }
)

【讨论】:

  • 是的,我做到了!但它只适用于信息量少的列...当我设置target=(hugetextcolumn) 它显示一个空表并且运行代码也需要很多时间...我想知道发生了什么=/
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-19
  • 2021-02-05
  • 1970-01-01
  • 2021-03-12
  • 1970-01-01
  • 2020-11-08
  • 2020-11-13
相关资源
最近更新 更多