【问题标题】:Add a scroll bar for datatable in shiny when using wellPanel使用wellPanel时为闪亮的数据表添加滚动条
【发布时间】:2020-06-12 06:04:49
【问题描述】:

当数据表包裹在fixedPanel 周围时,我正在尝试为它添加一个 X 滚动条。请参阅以下示例:

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

ui <- function(request) {
  dashboardPage(
    skin = "black",
    dashboardHeader(), 
    dashboardSidebar(disable = TRUE),
    dashboardBody(
      fluidRow(
        uiOutput("table")
      ),
      fluidRow(
        DT::dataTableOutput("data2")
      )
    )
  )
}

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

  output[["data"]] <-
        DT::renderDataTable({
         cbind(iris, iris, iris, iris, iris)[1, ]
        }, 
        selection = "none",
        options = list(
          searching = FALSE,
          lengthChange = FALSE,
          paginate = FALSE,
          scroller = TRUE,
          scrollX = TRUE
        ))

      output[["table"]] <-
        renderUI({
          fixedPanel(
          wellPanel(div(style = 'overflow-x: scroll', DT::dataTableOutput("data"))),
              style = "z-index: 10;"
          )
        })

      output[["data2"]] <-
        DT::renderDataTable({
          cbind(iris, iris, iris, iris, iris)
        }, 
        options = list(
          scroller = TRUE,
          scrollX = TRUE,
          pageLength = 25
        ))
}

shinyApp(ui, server)

相反,我可以使用闪亮的box 对象并且滚动工作,但是我在我的应用程序中需要的其他 ui (style = "z-index: 10;") 之上没有此数据表:

      output[["table"]] <-
        renderUI({
          box(div(style = 'overflow-x: scroll', DT::dataTableOutput("data")),
              width = 12,
              style = "z-index: 10;") # this line doesn't work

        })

这两者可以结合吗?我宁愿使用fixedPanel 而不是box,但我需要数据表中的两个组件:滚动和位于其他 ui 输出之上。

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    看到这个帖子:https://stackoverflow.com/a/55574864/3439739

    renderUI({
      fixedPanel(
        wellPanel(div(style = 'overflow-x: scroll', DT::dataTableOutput("data"))),
            style = "z-index: 10; left:0; right:0; overflow-y:hidden; overflow-xy:auto"
      )
    })
    

    似乎可以胜任。

    【讨论】:

      猜你喜欢
      • 2019-02-22
      • 2018-05-10
      • 2015-10-27
      • 2015-03-12
      • 1970-01-01
      • 2018-10-27
      • 2018-07-06
      • 2020-03-04
      • 1970-01-01
      相关资源
      最近更新 更多