【问题标题】:How to render entire DT table left justified on the page in Shiny?如何在 Shiny 的页面上呈现整个 DT 表左对齐?
【发布时间】:2018-02-01 14:07:58
【问题描述】:

我的一些 DT 表似乎位于页面的中心(参见下面的图 1 和图 2)。如何使它们在左侧对齐,以便所有表格和绘图都很好地对齐。

生成第一个表的代码(“集群解决方案摘要”)

output$out_best <- DT::renderDataTable({
  #if (input$act_access_k >0) {
    DT::datatable(best_sols(), caption = "", rownames = TRUE,
      options = list(autoWidth = TRUE, scrollX = TRUE,
      columnDefs = list(list(width = '100px', targets = 1)),
      paging = FALSE, searching = FALSE), selection='none') %>% formatRound(1:input$Bn, 3)
  #}
})

我生成第二张表的代码(“...按集群分布”)

output$prop_by_cluster <- DT::renderDataTable({
  if (input$act_next3 >0 & input$act_clust_sel>0) {
    DT::datatable(profile_result(), class= 'compact stripe', caption = '',
      rownames = F, options = list(autoWidth = TRUE, scrollX = TRUE,
      columnDefs = list(list(width = '200px', targets = 1)),
      paging = FALSE, searching = FALSE)) %>% formatPercentage(1: max(input$k)+2, 2)  
  }
}) 

编辑

添加之前 style = "float:left"

添加后样式 = "float:left"

【问题讨论】:

  • 我用renderDataTable做了很多尝试;但找不到与server 对齐的方法。但是,您可以从 ui 执行此操作,如下所示:mainPanel(style = "float:left", dataTableOutput("out_best"), dataTableOutput("prop_by_cluster "))
  • Sagar - 您的建议可以对齐左侧的表格。然而,另一张桌子/情节似乎被弄脏了。请参阅我原始帖子中附加的图像。任何想法?谢谢!
  • 看起来您的表格都是左对齐的,但有些列没有正确对齐。需要对齐这些。

标签: r datatable shiny render


【解决方案1】:

尝试将其添加到 UI 部分的页面正文中。

ui.R:

tags$head(tags$style(".datatables .display {margin-left: 0;}"))

【讨论】:

  • 这是跟随 mainPanel() 函数还是 UI 中的其他地方?
猜你喜欢
  • 1970-01-01
  • 2011-01-02
  • 2022-08-24
  • 2020-09-06
  • 2017-10-26
  • 2016-05-31
  • 2023-03-04
  • 2021-11-15
  • 1970-01-01
相关资源
最近更新 更多