我想在 dataTableOutput 中显示周过滤器,并按升序排列值。
这是ui.R
的代码fluidPage(
titlePanel("Delivery Assurance Matrix"),
fluidRow(
column(4,
selectInput("week_count",
"Week",
c("All",
sort(unique(as.character(data$Week))))
))),
DT::dataTableOutput("table")
)
这是server.R
的代码function(input, output) {
output$table <- DT::renderDataTable(DT::datatable({
data<-data
if (input$week_count != "All") {
data <- data[data$Week >= input$week_count,]
}
data
}))
}
您也可以购买
shinyWidgets
套餐,其中有 Select All
选项
library(shiny)
library(shinyWidgets)
data <- c(11,1,2,3,10,21)
ui <- fluidPage(
titlePanel("Delivery Assurance Matrix"),
fluidRow(
column(4,
pickerInput(
inputId = "week_count",
label = "Week",
choices = sort(data),
multiple = TRUE,
options = list(
`actions-box` = TRUE,
`deselect-all-text` = "None...",
`select-all-text` = "Select All",
`none-selected-text` = "None Selected"
)
)
)),
DT::dataTableOutput("table")
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
通过此更改解决了。
fluidRow(
column(4,
selectInput("week_count",
"Week",
c("All",
order(sort(unique(as.character(data$Week)))))
))