Skip to main content

tags: [gradio-custom-component, SimpleTextbox, gradio pagination] title: gradio_pagination short_description: pagination component colorFrom: blue colorTo: yellow sdk: gradio pinned: false app_file: space.py

gradio_pagination

PyPI - Version

pagination component

Installation

pip install gradio_pagination

Usage

import json

import gradio as gr
from gradio_pagination import pagination

total=10000
current_page = 1
page_size = 10
page_size_options = [10, 20, 30, 50, 300]

def rerender_pagination_total(total_num):
    global total, page_size, current_page, page_size_options
    total = int(total_num)
    current_page = 1 # If the total number changes, whether to reset the current page to 1 depends on your business logic.
    print('overide total to ', total)
    return json.dumps({
        "total": int(total),
        "page": int(current_page),
        "page_size": int(page_size),
        "page_size_options": page_size_options,
    })

def rerender_pagination_page(page):
    global total, page_size, current_page, page_size_options
    current_page = int(page)
    print('overide current_page to ', current_page)
    return json.dumps({
        "total": int(total),
        "page": int(current_page),
        "page_size": int(page_size),
        "page_size_options": page_size_options,
    })

def rerender_pagination_size(size):
    global total, page_size, current_page, page_size_options
    page_size = int(size)
    print('overide page_size to ', page_size)
    return json.dumps({
        "total": int(total),
        "page": int(current_page),
        "page_size": int(page_size),
        "page_size_options": page_size_options,
    })

def rerender_pagination_size_options(options: str):
    global total, page_size, current_page, page_size_options
    try:
        page_size_options = list(map(int, options.split(',')))
        print('overide page_size_options to ', page_size_options)
    except ValueError as e:
        print(f"{e}, the options str is: {options}")
    return json.dumps({
        "total": int(total),
        "page": int(current_page),
        "page_size": int(page_size),
        "page_size_options": page_size_options,
    })

def show_page_info_into_text_box(data):
    global total, page_size, current_page, page_size_options
    current_page = data.page
    page_size = data.page_size
    total = data.total
    page_size_options = data.page_size_options
    print('pagination change: ', data)
    return str(current_page), str(page_size), str(total), ",".join(map(str, sorted(page_size_options)))

with gr.Blocks() as demo:
    gr.Markdown("## Pagination Demo")
    pagination_component = pagination(total=total, page=1, page_size=10, page_size_options=page_size_options)

    with gr.Row():
        page_display = gr.Textbox(label="Current Page", value=str(current_page), interactive=True)
        size_display = gr.Textbox(label="Page Size", value=str(page_size), interactive=True)
        total_display = gr.Textbox(label="Total", value=str(total), interactive=True)
        options_display = gr.Textbox(label="Page Size Options", value=str(",".join(map(str, page_size_options))), interactive=True)

    pagination_component.change(
        fn=show_page_info_into_text_box,
        inputs=pagination_component,
        outputs=[page_display, size_display, total_display, options_display]
    )
    page_display.change(fn=rerender_pagination_page, inputs=page_display, outputs=pagination_component)
    size_display.change(fn=rerender_pagination_size, inputs=size_display, outputs=pagination_component)
    total_display.change(fn=rerender_pagination_total, inputs=total_display, outputs=pagination_component)
    options_display.change(fn=rerender_pagination_size_options, inputs=options_display, outputs=pagination_component)

if __name__ == "__main__":
    demo.launch()

pagination

Initialization

name type default description
value
str | Callable | None
None None
placeholder
str | None
None None
label
str | None
None None
every
Timer | float | None
None None
inputs
Component | Sequence[Component] | set[Component] | None
None None
show_label
bool | None
None None
scale
int | None
None None
min_width
int
160 None
interactive
bool | None
None None
visible
bool
True None
rtl
bool
False None
elem_id
str | None
None None
elem_classes
list[str] | str | None
None None
render
bool
True None
key
int | str | None
None None
total
int | None
0 None
page
int | None
1 None
page_size
int | None
10 None
page_size_options
list[int] | None
[10, 20, 50, 100] None

Events

name description
change Triggered when the value of the pagination changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, str | None: Returns a namespace object representing the pagination state.
def predict(
    value: str | None
) -> str | None:
    return value

Metadata

Release files for gradio-pagination 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gradio-pagination 0.0.5
File Size Uploaded
gradio_pagination-0.0.5.tar.gz 59.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gradio-pagination 0.0.5
File Interpreter ABI Platform
gradio_pagination-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 77.0 kB

Release files / gradio_pagination-0.0.5.tar.gz

Download URL gradio_pagination-0.0.5.tar.gz
Size 59.4 kB
Tags Source
SHA-256 checksum
How to use checksums
69f916ec0961f43ed78f90c6e100ec8f378ca5e69b7e0fff3b1a853bed81d958
BLAKE2b-256 checksum
How to use checksums
5f9d43d4d8e5687f956a8c19eca089fc34a8fc45e5c728ec39d76279236e774a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / gradio_pagination-0.0.5-py3-none-any.whl

Download URL gradio_pagination-0.0.5-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87ddc94557dabc8d337b8f317353d9e05068f15dd2798136a2a82ac135036200
BLAKE2b-256 checksum
How to use checksums
bd2488e021b63d3f7338fad39f32b077b03345f2c87b62104d296ebb9b01694e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page