A pager module to add pagination to any collection of items. Given a number of items and a page break, the pagination module returns the indexes of the items on the currently selected page.
pager(id, n_items, page_break = 20) paginationUI(id, width = 6, ..., offset = 3) pagerUI(id, label_prev = "Previous", label_next = "Next", centered = TRUE, class = NULL) pagerDemo(display.mode = c("showcase", "normal", "auto"))
id | The shared |
---|---|
n_items | The number of items in the collection of items to be paged |
page_break | The maximum number of items in each page |
width | The width of the containing column |
... | Additional elements included in the containg column, added before the pagniation buttons |
offset | The offest of the containing column |
label_prev | The label of the "Previous" button. |
label_next | The label of the "Next" button". |
centered | If |
class | Additional classes applied to the |
display.mode | The mode in which to display the application. If set to
the value |
paginationUI
: The user interface for the pager module. The pager is
contained in a single column in a fluidRow()
.
pagerUI
: Next/previous buttons that can be used in addition to,
or in place of paginationUI()
.
pagerDemo
: Example app demonstrating usage of the pager module.
https://getbootstrap.com/docs/3.3/components/#pagination
if (interactive()) { library(shiny) ui <- fluidPage( titlePanel("shinyThings Pagination"), sidebarLayout( sidebarPanel( width = 6, tags$h4("paginationUI()"), shinyThings::paginationUI("pager", width = 12, offset = 0, class = "text-center"), tags$hr(), sliderInput("page_break", "Page Size", min = 1, max = 6, step = 1, value = 3), helpText(tags$code("page_break")), tags$hr(), tags$h4("pagerUI()"), shinyThings::pagerUI("pager", centered = FALSE) ), mainPanel( width = 6, tags$p("Page indices:"), verbatimTextOutput("page_indices"), tags$p(HTML("Paged output (<code>letters</code>):")), uiOutput("paged_output") ) ) ) server <- function(input, output) { ## page_break and n_items can be reactive or fixed values # page_break <- 4 # n_items <- length(letters) n_items <- reactiveVal(length(letters)) page_break <- reactive({input$page_break}) page_indices <- shinyThings::pager("pager", n_items, page_break) output$page_indices <- renderPrint({ page_indices() }) output$paged_output <- renderUI({ tags$ul( lapply(letters[page_indices()], tags$li) ) }) } shinyApp(ui, server) }