将DataTable放入shinydashboard框中

dy1byipe  于 2023-04-03  发布在  其他
关注(0)|答案(1)|浏览(85)

我已经阅读了所有类似问题的答案,没有一个奏效。非常简单的问题:我如何得到datatable来填充这个框?下面是一个reprex:

## UI

ui <- dashboardPage(
  
  dashboardHeader(disable=TRUE),
  dashboardSidebar(),
  dashboardBody(
    
    tabsetPanel(
      
      tabPanel("Main Tab",
               fluidRow(box(title = "Test",width=6,column(12,DTOutput("table1")),height=400)
                        ),
               )
    )
    
  )
)

# Server logic
server <- function(input, output) {
  
  output$table1 <- renderDT({
      iris %>% 
        datatable(options = list(dom = "t", scrollX = TRUE))
  })
  
}

# Run the application 
shinyApp(ui = ui, server = server)
cbwuti44

cbwuti441#

一种方法是使用scrollY参数:

library(shinydashboard)
library(shiny)
library(DT)

ui <- dashboardPage(
  
  dashboardHeader(disable=TRUE),
  dashboardSidebar(),
  dashboardBody(
    
    tabsetPanel(
      
      tabPanel("Main Tab",
               fluidRow(box(title = "Test",width=6,column(12,DTOutput("table1")),height=400)
               ),
      )
    )
    
  )
)

# Server logic
server <- function(input, output) {
  
  output$table1 <- renderDT({
    iris %>% 
      datatable(options = list(scrollX = TRUE,
                               scrollY = "200px"))
  })
  
}

# Run the application 
shinyApp(ui = ui, server = server)

相关问题