A paging input for R/Shiny applications
JavaScript R
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
www/js
.gitignore
LICENSE
README.md
global.R
pager-ui.Rproj
pager-ui_widget_screenshot.png
pagerui.R
server.R
ui.R

README.md

Pager UI

A generic pager widget for R/Shiny based applications.

pager-ui widget

Features

  • Prev / Next buttons
  • Dynamically rendered page number buttons
    • displays all if ≤ 10 pages
    • smart display of spacer ... buttons for larger ranges
  • R functions pageruiInput() (for ui.R) and updatePageruiInput() (for server.R) make it simple to use in any Shiny application

Application

Provide paging abilities to data sets that require more processing / rendering than a table.

Run the demo

If not already done, install the shiny R-package from CRAN:

install.packages('shiny')

Clone this git repository, navigate to the directory where ui.R and server.R are located and run:

shiny::runApp()

Use the widget

  1. Copy the folder www/js to your app.
  2. Copy pagerui.R to your app.
  3. In the global.R file (create it if it doesn't exist) add the line:
source('pagerui.R')
  1. In ui.R add the widget as needed using pageruiInput().
  2. In server.R use updatePageruiInput() in reactive contexts that need to update the widget.

Examples

In ui.R:

  • add a pager with id pager:
pageruiInput('pager')
  • add a pager-ui with id pager and initial current page of 5, initial total pages 10:
pageruiInput('pager', page_current = 5, pages_total = 10)

In server.R:

  • retrieve the current value from a pager-ui with id pager
pager_state = input$pager

## str(pager_state) 
##> List of 2
##>  $ page_current: int 1
##>  $ pages_total : int 4
  • update the current page of a pager-ui with id pager
updatePageruiInput(session, 'pager', page_current = new_page_current)
  • update the total number of pages available on a pager-ui with id pager
updatePageruiInput(session, 'pager', pages_total = new_pages_total)
  • update both the current page and total number of pages for a pager-ui with id pager
updatePageruiInput(session, 'pager', 
                   page_current = new_page_current, 
                   pages_total = new_pages_total)