Skip to main content

pagination component

Project description


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

def rerender_pagination_total(total_num):
    global total, page_size, current_page
    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)
    })

def rerender_pagination_page(page):
    global total, page_size, current_page
    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)
    })

def rerender_pagination_size(size):
    global total, page_size, current_page
    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)
    })

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

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

    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)

    pagination_component.change(
        fn=show_page_info_into_text_box,
        inputs=pagination_component,
        outputs=[page_display, size_display, total_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)

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_pagination-0.0.3.tar.gz (58.5 kB view details)

Uploaded Source

Built Distribution

gradio_pagination-0.0.3-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file gradio_pagination-0.0.3.tar.gz.

File metadata

  • Download URL: gradio_pagination-0.0.3.tar.gz
  • Upload date:
  • Size: 58.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for gradio_pagination-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3b3912a03f9c927707c3765ab4b414559faa7b1b5685c409975bd65a7c9a371a
MD5 ab03d1dcc841b7c182729f5ddd8476aa
BLAKE2b-256 ed84b0431cb1e7c7ffd00f65968fe06954b284ac2c6849c8d24f6d3cc5349480

See more details on using hashes here.

File details

Details for the file gradio_pagination-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_pagination-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f66bebf834c2a07e0386fc7b374861bae49f7b2778866279dea13a3126278da0
MD5 382d7059abc60991a82dbe152dbe4666
BLAKE2b-256 cf0142226a3cf37db7a9587b270df3c7179324847473363a19f6fd8cf527ac4e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page