gradio-pagination


Namegradio-pagination JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
Summarypagination component
upload_time2024-11-25 08:50:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache-2.0
keywords gradio pagination gradio-custom-component gradio-template-simpletextbox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ---
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`
<a href="https://pypi.org/project/gradio_pagination/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_pagination"></a>  

pagination component

## Installation

```bash
pip install gradio_pagination
```

## Usage

```python
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

<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">

```python
str | Callable | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>placeholder</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">

```python
Timer | float | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>inputs</code></td>
<td align="left" style="width: 25%;">

```python
Component | Sequence[Component] | set[Component] | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">

```python
int
```

</td>
<td align="left"><code>160</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>interactive</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>rtl</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>False</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">

```python
list[str] | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>key</code></td>
<td align="left" style="width: 25%;">

```python
int | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>total</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>0</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>page</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>1</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>page_size</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>10</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>page_size_options</code></td>
<td align="left" style="width: 25%;">

```python
list[int] | None
```

</td>
<td align="left"><code>[10, 20, 50, 100]</code></td>
<td align="left">None</td>
</tr>
</tbody></table>


### 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.


 ```python
 def predict(
     value: str | None
 ) -> str | None:
     return value
 ```
 

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gradio-pagination",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "gradio pagination, gradio-custom-component, gradio-template-SimpleTextbox",
    "author": null,
    "author_email": "YOUR NAME <YOUREMAIL@domain.com>",
    "download_url": "https://files.pythonhosted.org/packages/5f/9d/43d4d8e5687f956a8c19eca089fc34a8fc45e5c728ec39d76279236e774a/gradio_pagination-0.0.5.tar.gz",
    "platform": null,
    "description": "---\ntags: [gradio-custom-component, SimpleTextbox, gradio pagination]\ntitle: gradio_pagination\nshort_description: pagination component\ncolorFrom: blue\ncolorTo: yellow\nsdk: gradio\npinned: false\napp_file: space.py\n---\n\n# `gradio_pagination`\n<a href=\"https://pypi.org/project/gradio_pagination/\" target=\"_blank\"><img alt=\"PyPI - Version\" src=\"https://img.shields.io/pypi/v/gradio_pagination\"></a>  \n\npagination component\n\n## Installation\n\n```bash\npip install gradio_pagination\n```\n\n## Usage\n\n```python\nimport json\n\nimport gradio as gr\nfrom gradio_pagination import pagination\n\ntotal=10000\ncurrent_page = 1\npage_size = 10\npage_size_options = [10, 20, 30, 50, 300]\n\ndef rerender_pagination_total(total_num):\n    global total, page_size, current_page, page_size_options\n    total = int(total_num)\n    current_page = 1 # If the total number changes, whether to reset the current page to 1 depends on your business logic.\n    print('overide total to ', total)\n    return json.dumps({\n        \"total\": int(total),\n        \"page\": int(current_page),\n        \"page_size\": int(page_size),\n        \"page_size_options\": page_size_options,\n    })\n\ndef rerender_pagination_page(page):\n    global total, page_size, current_page, page_size_options\n    current_page = int(page)\n    print('overide current_page to ', current_page)\n    return json.dumps({\n        \"total\": int(total),\n        \"page\": int(current_page),\n        \"page_size\": int(page_size),\n        \"page_size_options\": page_size_options,\n    })\n\ndef rerender_pagination_size(size):\n    global total, page_size, current_page, page_size_options\n    page_size = int(size)\n    print('overide page_size to ', page_size)\n    return json.dumps({\n        \"total\": int(total),\n        \"page\": int(current_page),\n        \"page_size\": int(page_size),\n        \"page_size_options\": page_size_options,\n    })\n\ndef rerender_pagination_size_options(options: str):\n    global total, page_size, current_page, page_size_options\n    try:\n        page_size_options = list(map(int, options.split(',')))\n        print('overide page_size_options to ', page_size_options)\n    except ValueError as e:\n        print(f\"{e}, the options str is: {options}\")\n    return json.dumps({\n        \"total\": int(total),\n        \"page\": int(current_page),\n        \"page_size\": int(page_size),\n        \"page_size_options\": page_size_options,\n    })\n\ndef show_page_info_into_text_box(data):\n    global total, page_size, current_page, page_size_options\n    current_page = data.page\n    page_size = data.page_size\n    total = data.total\n    page_size_options = data.page_size_options\n    print('pagination change: ', data)\n    return str(current_page), str(page_size), str(total), \",\".join(map(str, sorted(page_size_options)))\n\nwith gr.Blocks() as demo:\n    gr.Markdown(\"## Pagination Demo\")\n    pagination_component = pagination(total=total, page=1, page_size=10, page_size_options=page_size_options)\n\n    with gr.Row():\n        page_display = gr.Textbox(label=\"Current Page\", value=str(current_page), interactive=True)\n        size_display = gr.Textbox(label=\"Page Size\", value=str(page_size), interactive=True)\n        total_display = gr.Textbox(label=\"Total\", value=str(total), interactive=True)\n        options_display = gr.Textbox(label=\"Page Size Options\", value=str(\",\".join(map(str, page_size_options))), interactive=True)\n\n    pagination_component.change(\n        fn=show_page_info_into_text_box,\n        inputs=pagination_component,\n        outputs=[page_display, size_display, total_display, options_display]\n    )\n    page_display.change(fn=rerender_pagination_page, inputs=page_display, outputs=pagination_component)\n    size_display.change(fn=rerender_pagination_size, inputs=size_display, outputs=pagination_component)\n    total_display.change(fn=rerender_pagination_total, inputs=total_display, outputs=pagination_component)\n    options_display.change(fn=rerender_pagination_size_options, inputs=options_display, outputs=pagination_component)\n\nif __name__ == \"__main__\":\n    demo.launch()\n\n```\n\n## `pagination`\n\n### Initialization\n\n<table>\n<thead>\n<tr>\n<th align=\"left\">name</th>\n<th align=\"left\" style=\"width: 25%;\">type</th>\n<th align=\"left\">default</th>\n<th align=\"left\">description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\"><code>value</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | Callable | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>placeholder</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>every</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nTimer | float | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>inputs</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nComponent | Sequence[Component] | set[Component] | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>show_label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>scale</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>min_width</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint\n```\n\n</td>\n<td align=\"left\"><code>160</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>interactive</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>visible</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>rtl</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>False</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_id</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_classes</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>render</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>key</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>total</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>0</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>page</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>1</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>page_size</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>10</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>page_size_options</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[int] | None\n```\n\n</td>\n<td align=\"left\"><code>[10, 20, 50, 100]</code></td>\n<td align=\"left\">None</td>\n</tr>\n</tbody></table>\n\n\n### Events\n\n| name | description |\n|:-----|:------------|\n| `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. |\n\n\n\n### User function\n\nThe impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).\n\n- When used as an Input, the component only impacts the input signature of the user function.\n- When used as an output, the component only impacts the return signature of the user function.\n\nThe code snippet below is accurate in cases where the component is used as both an input and an output.\n\n- **As output:** Is passed, str | None: Returns a namespace object representing the pagination state.\n\n\n ```python\n def predict(\n     value: str | None\n ) -> str | None:\n     return value\n ```\n \n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "pagination component",
    "version": "0.0.5",
    "project_urls": null,
    "split_keywords": [
        "gradio pagination",
        " gradio-custom-component",
        " gradio-template-simpletextbox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd2488e021b63d3f7338fad39f32b077b03345f2c87b62104d296ebb9b01694e",
                "md5": "4c1ce1921f5857a0b4c61ca438586a5e",
                "sha256": "87ddc94557dabc8d337b8f317353d9e05068f15dd2798136a2a82ac135036200"
            },
            "downloads": -1,
            "filename": "gradio_pagination-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4c1ce1921f5857a0b4c61ca438586a5e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17606,
            "upload_time": "2024-11-25T08:50:11",
            "upload_time_iso_8601": "2024-11-25T08:50:11.346280Z",
            "url": "https://files.pythonhosted.org/packages/bd/24/88e021b63d3f7338fad39f32b077b03345f2c87b62104d296ebb9b01694e/gradio_pagination-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f9d43d4d8e5687f956a8c19eca089fc34a8fc45e5c728ec39d76279236e774a",
                "md5": "061f9d1c6bed3ab435d5a10b259cc770",
                "sha256": "69f916ec0961f43ed78f90c6e100ec8f378ca5e69b7e0fff3b1a853bed81d958"
            },
            "downloads": -1,
            "filename": "gradio_pagination-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "061f9d1c6bed3ab435d5a10b259cc770",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 59403,
            "upload_time": "2024-11-25T08:50:13",
            "upload_time_iso_8601": "2024-11-25T08:50:13.335525Z",
            "url": "https://files.pythonhosted.org/packages/5f/9d/43d4d8e5687f956a8c19eca089fc34a8fc45e5c728ec39d76279236e774a/gradio_pagination-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-25 08:50:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gradio-pagination"
}
        
Elapsed time: 1.33250s