【问题标题】:formatting data table in RShiny在 RShiny 中格式化数据表
【发布时间】:2021-01-13 20:13:13
【问题描述】:

对于我的数据表,我有以下ui.R 文件:

tabItem(tabName = "maForwardVsSpot", fluidRow(DT::dataTableOutput(outputId = "maForwardVsSpotTABLE"))

我的server.R 看起来像这样:

output$maForwardVsSpotTABLE <- DT::renderDataTable({

      DT::datatable(dt.FvsS, rownames = FALSE, escape = FALSE, class = 'cell-border stripe',
                    colnames = c("Date", "Spot", input$maStrategy, "Mean Difference"),
                    options = list(pageLength = 10, autoWidth = TRUE, scrollX = TRUE,
                                   columnDefs = list(list(className = 'dt-center', targets = c(0,1,2,3), width = '200px')),
                                   initComplete = JS("function(settings, json) {",
                                                     "$(this.api().table().header()).css({'background-color': '#007d3c', 'color': '#fff'});",
                                                     "}")
                    )
      )
  
})

这会导致以下数据表,其中红色圈出的部分不适合我,因为它们应该与数据表齐平,并且左右距离不远。

【问题讨论】:

  • 我从未见过。你试过class = 'display cell-border stripe'吗?
  • 是的,我已经尝试过了,它并没有改变任何东西..

标签: r shiny datatables dt column-width


【解决方案1】:

这似乎有效:

tabItem(
  tabName = "maForwardVsSpot", 
  tags$div(
    style = "width: fit-content;",
    DT::dataTableOutput(outputId = "maForwardVsSpotTABLE")
  )
)

【讨论】:

    猜你喜欢
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多