我已经编写了用于简单仪表板的代码以显示表格
1)我已经使用了renderDT函数
2)由于表很大,因此我尝试使用scrollX进行水平滑动,这是行不通的。
3)同样,默认情况下,我也只能看到3列,如何增加要显示的列数?
下面是代码
library(shinydashboard)
library(leaflet)
library(ggplot2)
library(DT)
library(openxlsx)
# -----------------------------------------------------------------------------
# Dashboard UI
# -----------------------------------------------------------------------------
dataset <- c("P1-Long-Term-Unemployment-Statistics","P1-OfficeSupplies")
ui <- dashboardPage(
dashboardHeader(
title = "Validation Tool"
),
dashboardSidebar(
------
-----
-----),
-----
-------
),
dashboardBody(
tabItems(
# Current location ------------------------------------------------------
tabItem(tabName = "view",
mainPanel(
titlePanel(h2("Explore Datasets")),fluidRow(
column(6,
selectInput("table",
"Table:",
dataset)
),
column(6,
uiOutput("sheets")
)
),
tabsetPanel(type="tab",
tabPanel("Data",br(),fluidRow(column(12,div(DT::dataTableOutput("table"))))
),
tabPanel("Summary"),
tabPanel("Plot")
)
)
)
)
)
)
# -----------------------------------------------------------------------------
# Dashboard server code
# -----------------------------------------------------------------------------
server <- function(input, output,session) {
my_file <- function(){
my_file <- paste0("D:/Dataset/",input$table,".xlsx")
}
sheetNames <- function(){
sheetNames <- getSheetNames(my_file())
}
output$sheets <- renderUI({
selectInput("sheet","Sheet:",choices = sheetNames())
})
output$table <- renderDT(read.xlsx(my_file(),sheet=as.character(input$sheet)),class="display nowrap compact",
filter = "top",options = list( # options
scrollX = T,
scrollCollapse=TRUE, pageLength=5,lengthMenu=c(5,10,15,20),
search = list(regex = FALSE, caseInsensitive = FALSE)))
# DT::renderDataTable(DT::datatable({
# data <- read.xlsx(my_file(),sheet=as.character(input$sheet))
# data
# }))
}
shinyApp(ui, server)
请帮助解决该问题