【问题标题】:Creating full-screen DT table widget in shiny gadget在闪亮的小工具中创建全屏 DT 表小部件
【发布时间】:2019-10-05 23:43:47
【问题描述】:

我正在尝试构建一个闪亮的小工具来使用 DT 库浏览数据表中的数据。我希望 DT 小部件填充整个闪亮的页面或屏幕,但表格以较低的固定高度呈现。如何让表格填充 UI?

我已经将 dataTableOutput 的高度参数设置为 100%,并且我尝试了不同的 UI 容器,例如 fillPage 而不是 miniUI。

这是我的代码的精简版:

library(shiny)
library(miniUI)
library(DT)

ViewDT <- function(data) {

  ui <- miniPage(
    DT::dataTableOutput("mytable1", height = "100%")
    )

  server <- function(input, output, session) {

    output$mytable1 <- DT::renderDataTable({
      table <- DT::datatable(data, 
                             extensions = c('Buttons','Scroller'), 
                             options = list(dom = 'BrtS', 
                                            buttons = I('colvis'),
                                            scrollY = 200,
                                            deferRender = TRUE,
                                            paging = T
                                            )
                             )
      })
  }

  runGadget(ui, server, viewer = dialogViewer("Data"))
}

ViewDT(iris)

结果:The table fills about half of the dialog viewer instead of its entirety.

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    您可以使用:fillContainer = TRUE:

    library(shiny)
    library(miniUI)
    library(DT)
    
    ViewDT <- function(data) {
    
      ui <- miniPage(
        DT::dataTableOutput("mytable1", height = "100%")
      )
    
      server <- function(input, output, session) {
    
        output$mytable1 <- DT::renderDataTable({
          table <- DT::datatable(data, 
                                 extensions = c('Buttons','Scroller'), 
                                 options = list(dom = 'BrtS', 
                                                buttons = I('colvis'),
                                                scrollY = 200,
                                                deferRender = TRUE,
                                                paging = TRUE
                                 ),
                                 fillContainer = TRUE
          )
        })
      }
    
      runGadget(ui, server, viewer = dialogViewer("Data"))
    }
    
    ViewDT(iris)
    

    【讨论】:

      猜你喜欢
      • 2019-07-28
      • 2022-01-12
      • 2023-03-25
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多