Skip to content

Commit

Permalink
added pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Nov 11, 2023
1 parent 177c8fe commit bf8fe7b
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export(navbar_item)
export(navbar_toggle)
export(nextui_page)
export(numeric_input)
export(pagination)
export(popover)
export(popover_content)
export(popover_trigger)
Expand Down Expand Up @@ -79,6 +80,7 @@ export(update_date_input)
export(update_dropdown)
export(update_listbox)
export(update_numeric_input)
export(update_pagination)
export(update_radio_input)
export(update_select_input)
export(update_slider_input)
Expand Down
4 changes: 0 additions & 4 deletions R/components.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ component <- function(name) {
avatar <- component("Avatar")

#' @rdname avatar
#' @inherit component params return
#' @export
avatar_group <- component("AvatarGroup")

Expand All @@ -33,17 +32,14 @@ button <- component("Button")
card <- component("Card")

#' @rdname card
#' @inherit component params return
#' @export
card_body <- component("CardBody")

#' @rdname card
#' @inherit component params return
#' @export
card_header <- component("CardHeader")

#' @rdname card
#' @inherit component params return
#' @export
card_footer <- component("CardFooter")

Expand Down
21 changes: 19 additions & 2 deletions R/inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ update_checkboxgroup_input <- function(
}

#' @rdname accordion
#' @inherit component params return
#' @inherit shinyInput params return
#' @export
accordion <- input("Accordion")

#' @rdname accordion
#' @inherit component params return
#' @export
accordion_item <- component("AccordionItem")

Expand Down Expand Up @@ -290,10 +291,12 @@ dropdown_section <- component("DropdownSection")
update_dropdown <- shiny.react::updateReactInput

#' @rdname listbox
#' @inherit shinyInput params return
#' @export
listbox <- input("Listbox")

#' @rdname listbox
#' @inherit component params return
#' @export
listbox_section <- component("ListboxSection")

Expand All @@ -305,23 +308,35 @@ listbox_item <- component("ListboxItem")
#' @export
update_listbox <- shiny.react::updateReactInput

#' @rdname pagination
#' @inherit shinyInput params return
#' @export
pagination <- input("Pagination", 1)

#' @rdname pagination
#' @export
update_pagination <- shiny.react::updateReactInput

#' @rdname select
#' @inherit shinyInput params return
#' @export
select_input <- input("Select", "")

#' @rdname select
#' @inherit component params return
#' @export
select_section <- component("SelectSection")

#' @rdname select
#' @export
select_item <- component("SelectItem")

#' @rdname sselect
#' @rdname select
#' @export
update_select_input <- shiny.react::updateReactInput

#' @rdname slider
#' @inherit shinyInput params return
#' @export
slider_input <- input("Slider", numeric())

Expand All @@ -330,6 +345,7 @@ slider_input <- input("Slider", numeric())
update_slider_input <- shiny.react::updateReactInput

#' @rdname tabs
#' @inherit shinyInput params return
#' @export
tabs <- input("Tabs", "1")

Expand All @@ -338,5 +354,6 @@ tabs <- input("Tabs", "1")
update_tabs <- shiny.react::updateReactInput

#' @rdname tabs
#' @inherit component params return
#' @export
tab <- component("Tab")
4 changes: 0 additions & 4 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,17 @@ spacer <- component("Spacer")
navbar <- component("Navbar")

#' @rdname navbar
#' @inherit component params return
#' @export
navbar_brand <- component("NavbarBrand")

#' @rdname navbar
#' @inherit component params return
#' @export
navbar_content <- component("NavbarContent")

#' @rdname navbar
#' @inherit component params return
#' @export
navbar_item <- component("NavbarItem")

#' @rdname navbar
#' @inherit component params return
#' @export
navbar_toggle <- component("NavbarToggle")
59 changes: 59 additions & 0 deletions inst/examples/pagination/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
library(shiny)
library(shinyNextUI)
library(shiny.react)
library(thematic)

thematic_shiny()

max <- 10
cards <- lapply(seq_len(max), function(i) {
tagList(
spacer(y = 2),
card(
id = sprintf("mycard-%s", i),
card_header(sprintf("Card %s", i)),
card_body(
sprintf("Card content %s", i),
slider_input(sprintf("obs-%s", i), "Obs", minValue = 0, maxValue = 1000, value = 500),
plotOutput(sprintf("distPlot-%s", i))
)
)
)
})

ui <- nextui_page(
pagination(
inputId = "pagination",
loop = TRUE,
size = "lg",
variant = "bordered",
showControls = TRUE,
page = 1,
total = max
)
)

server <- function(input, output, session) {

history <- reactiveVal(NULL)

# Dynamically insert cards with the pagination.
observeEvent(input$pagination, {
if (!is.null(history())) removeUI(sprintf("#mycard-%s", history()), multiple = TRUE)
insertUI(
selector = "#pagination",
where = "afterEnd",
ui = cards[[input$pagination]]
)
history(input$pagination)

output[[sprintf("distPlot-%s", history())]] <- renderPlot({
hist(
rnorm(input[[sprintf("obs-%s", history())]]),
main = sprintf("Super plot %s", history())
)
})
})
}

if (interactive() || is_testing()) shinyApp(ui, server)
1 change: 1 addition & 0 deletions inst/helpers/doc/generate-doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ items <- list(
"listbox",
"modal",
"navbar",
"pagination",
"popover",
"progress",
"radio",
Expand Down
2 changes: 1 addition & 1 deletion inst/nextui-2.0.0/nextui.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions js/src/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ export const Listbox = InputAdapter(NextUI.Listbox, (value, setValue, props) =>
}
}));

export const Pagination = InputAdapter(NextUI.Pagination, (value, setValue, props) => ({
page: value,
onChange: (page) => {
setValue(page);
},
}));

export const Select = InputAdapter(NextUI.Select, (value, setValue, props) => {
const [touched, setTouched] = React.useState(true);

Expand Down
4 changes: 1 addition & 3 deletions man/checkbox-group.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/radio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/test-pagination.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(shinytest2)
test_that("pagination works as expected", {
# Don't run these tests on the CRAN build servers
skip_on_cran()
shiny_app_path <-
system.file("examples/pagination/app.R", package = "shinyNextUI")
app <- AppDriver$new(
shiny_app_path,
name = "pagination-app",
variant = platform_variant()
)
app$expect_values()
})

0 comments on commit bf8fe7b

Please sign in to comment.