Shiny应用UI端data table布局及列头锁定问题求助
解决方法
问题1:Original Data标签页表格与全局配置栏并排显示
shinydashboard基于Bootstrap 12列栅格系统布局,全局配置侧边栏已设置宽度为2,剩余可分配宽度为10列,给Original标签页的表格组件外层包裹宽度为10的column容器即可实现并排布局,不会出现换行下沉的问题。
问题2:box内部表格滚动时锁定列头
去掉box组件的自定义滚动样式,直接使用DT组件原生的固定表头参数即可实现需求。DT的fixedHeader配置会接管组件自身的滚动事件,不受外层box容器影响,滚动时列头会固定在顶部。
修改后完整代码
library(shiny) library(lubridate) library(tidyverse) library(DT) library(shinydashboard) library(shinythemes) library(sortable) library(reactlog) ui<- dashboardPage( #this gives you the name displayed on the tab dashboardHeader(title = "HHS Resin Purchasing 0.99"), #this gives you your sidebar (page) options dashboardSidebar( sidebarMenu( menuItem("Original Data", tabName = "original"), menuItem("Suggested", tabName = "suggested") ) ), #this is the body of the webpages dashboardBody( #this gives you the body options that are displayed on every page sidebarPanel(width = 2, h2("Menu Options"), h4(strong("Upload Data:")), fileInput("file", "Data", buttonLabel = "Upload..."), textInput("delim", "Delimiter (leave blank to guess)", ""), numericInput("skip", "Rows to skip", 0, min = 0), h4(strong("User Options:")), selectInput("plant", "Select a Plant", choices = c("All")), dateInput("latest_date", "Select the latest W_LEAD date in the data", value = Sys.Date()), numericInput("avg_multiple", "Multiple of Daily Useage for Cuttoff",21, min = 1, max = 50), h4(strong("Download Options:")), actionButton("complete_orders", "Analysis for plant orders complete"), actionButton("complete_checks", "Mid month check complete"), downloadButton("downloadData1", label = "Download Suggested Orders...", class = "btn-block"), downloadButton("downloadData2", label = "Download Flags...", class = "btn-block"), downloadButton("downloadData3", label = "Download Full Suggested Orders Data...", class = "btn-block") ), #This is the actual data that fills those page options listed above tabItems( tabItem(tabName = "original", column(width = 10, DT::dataTableOutput(outputId = "preview1") ) ), tabItem(tabName = "suggested", box(title = "Suggested Orders",width = 9, status = "primary", height = "auto", solidHeader = T, dataTableOutput("preview2")) ) ) ) ) server <- function(input, output) { output$preview1 <- renderDataTable({ DT::datatable(iris, options = list(searching = T, pageLength = 20, lengthMenu = c(5,10,15, 20))) }) output$preview2 <- renderDataTable({ DT::datatable(iris, options = list( searching = T, pageLength = 20, lengthMenu = c(5,10,15, 20), fixedHeader = TRUE, scrollY = "700px", scrollX = TRUE )) }, server = FALSE) } shinyApp(ui, server)
内容的提问来源于stack exchange,提问作者tfr950
相关产品推荐
相关产品推荐

