├── LICENSE ├── MANIFEST.in ├── README.md ├── img ├── empty └── pagination.jpg ├── setup.py └── streamlit_pagination ├── __init__.py ├── frontend ├── package-lock.json ├── package.json ├── public │ ├── bootstrap.min.css │ └── index.html ├── src │ ├── PaginationComponent.tsx │ ├── index.tsx │ └── react-app-env.d.ts └── tsconfig.json └── style.css /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2021 Streamlit Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include streamlit_pagination/frontend/build * 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # streamlit-pagination 2 | Mui pagination component to segment data by numbered pages 3 | 4 | 5 | Its built on the streamlit custom components typescript template 6 | 7 | To install it: 8 | 9 | ``` 10 | pip install streamlit-pagination 11 | ``` 12 | 13 | Variables 14 | - dataLength: length of data that will be displayed (rows/index) 15 | - layout: dictionary variable to determine what the layout of the mui component will look like including the style 16 | 17 | You need to import the style file which adjusts the size of the iframe - it can be found [here](https://github.com/Socvest/streamlit-pagination/tree/main/streamlit_pagination). 18 | 19 | ``` 20 | import streamlit as st 21 | import pandas as pd 22 | import numpy as np 23 | from streamlit_pagination import pagination_component 24 | 25 | st.markdown('', unsafe_allow_html=True) 26 | 27 | words = ['light', 'bed', 'colorful', 'boiling', 'well-off', 'overrated', 'immense', 'hard', 'relieved', 'precious', 'ludicrous', 'eatable', 'cruel', 'discovery', 'sloppy', 'tray', 'disagreeable', 'telephone', 'lovely', 'godly', 'cause', 'pointless', 'theory', 'spooky', 'drop', 'bite-sized', 'reminiscent', 'wicked', 'hug', 'hate', 'ashamed', 'unused', 'jazzy', 'known', 'chief', 'disapprove', 'admit', 'gaping', 'vivacious', 'hollow', 'eight', 'popcorn', 'exciting', 'whimsical', 'faint', 'new', 'tire', 'pizzas', 'internal', 'effect', 'start', 'unarmed', 'worm', 'awake', 'string', 'humor', 'cautious', 'notebook', 'wide-eyed', 'month', 'same', 'cover', 'receive', 'clover', 'misty', 'step', 'dislike', 'vague', 'flat', 'neck', 'voice', 'stitch', 'apparatus', 'boundless', 'lunchroom', 'team', 'receipt', 'disagree', 'ruin', 'meeting', 'honorable', 'groovy', 'cherry', 'scissors', 'bizarre', 'steady', 'cannon', 'ship', 'soothe', 'mundane', 'verdant', 'tiger', 'request', 'home', 'quizzical', 'head', 'loving', 'interfere', 'argument', 'imported'] 28 | 29 | def random_char(y): 30 | 31 | return words[:y] 32 | 33 | def data_chunk_choice(): 34 | if 'foo' not in st.session_state: 35 | return 0 36 | return st.session_state['foo'] 37 | 38 | data = pd.DataFrame(np.random.randint(0,100,size=(1000, 4))), columns=list('ABCD')) 39 | 40 | n = 100 41 | list_df = [data[i:i+n] for i in range(0,data.shape[0],n)] 42 | 43 | data_l = list_df[data_chunk_choice()] 44 | 45 | st.dataframe(data_l, width=400, height=700) 46 | 47 | layout = { 'color':"primary", 48 | 'style':{'margin-top':'10px'}} 49 | test = pagination_component(len(list_df), layout=layout, key="foo") 50 | ``` 51 | ![pagination.jpg](./img/pagination.jpg) 52 | -------------------------------------------------------------------------------- /img/empty: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /img/pagination.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Socvest/streamlit-pagination/953524309709a90b01b11c742d1ec27c92fabecf/img/pagination.jpg -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | setuptools.setup( 4 | name="streamlit-pagination", 5 | version="0.0.3", 6 | author="", 7 | author_email="", 8 | description="", 9 | long_description="", 10 | long_description_content_type="text/plain", 11 | url="", 12 | packages=setuptools.find_packages(), 13 | include_package_data=True, 14 | classifiers=[], 15 | python_requires=">=3.6", 16 | install_requires=[ 17 | # By definition, a Custom Component depends on Streamlit. 18 | # If your component has other Python dependencies, list 19 | # them here. 20 | "streamlit >= 0.63", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /streamlit_pagination/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import streamlit.components.v1 as components 3 | 4 | _RELEASE = True 5 | 6 | if not _RELEASE: 7 | _pagination_component = components.declare_component( 8 | "pagination_component", 9 | url="http://localhost:3001", 10 | ) 11 | else: 12 | parent_dir = os.path.dirname(os.path.abspath(__file__)) 13 | build_dir = os.path.join(parent_dir, "frontend/build") 14 | _pagination_component = components.declare_component("pagination_component", path=build_dir) 15 | 16 | def pagination_component(dataLength, layout, key=None): 17 | 18 | component_value = _pagination_component(dataLength=dataLength, layout=layout, key=key, default=0) 19 | 20 | return component_value 21 | 22 | 23 | # if not _RELEASE: 24 | # import streamlit as st 25 | # import pandas as pd 26 | # import numpy as np 27 | # from streamlit_pagination import pagination_component 28 | 29 | # st.markdown('', unsafe_allow_html=True) 30 | 31 | # if 'foo' not in st.session_state: 32 | # st.session_state['foo'] = 0 33 | 34 | # data = pd.DataFrame(np.random.randint(0,100,size=(1000, 4)), columns=list('ABCD')) 35 | 36 | # n = 100 37 | # list_df = [data[i:i+n] for i in range(0,data.shape[0],n)] 38 | 39 | # data_l = list_df[st.session_state['foo']] 40 | 41 | # st.dataframe(data_l, width=300, height=700) 42 | 43 | # layout = { 'color':"primary", 44 | # 'style':{'margin-top':'10px'}} 45 | # test = pagination_component(len(list_df), layout=layout, key="foo") 46 | -------------------------------------------------------------------------------- /streamlit_pagination/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "streamlit_component_template", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/lab": "^4.0.0-alpha.61", 7 | "@nivo/circle-packing": "^0.79.1", 8 | "@types/jest": "^24.0.0", 9 | "@types/node": "^12.0.0", 10 | "@types/react": "^16.9.0", 11 | "@types/react-dom": "^16.9.0", 12 | "react": "^16.13.1", 13 | "react-dom": "^16.13.1", 14 | "react-paginate": "^8.1.3", 15 | "react-scripts": "3.4.1", 16 | "streamlit-component-lib": "^1.3.0", 17 | "typescript": "~3.8.0" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": "react-app" 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | }, 40 | "homepage": "." 41 | } 42 | -------------------------------------------------------------------------------- /streamlit_pagination/frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Streamlit Component 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /streamlit_pagination/frontend/src/PaginationComponent.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | ComponentProps, 3 | Streamlit, 4 | StreamlitComponentBase, 5 | withStreamlitConnection, 6 | } from "streamlit-component-lib" 7 | import React, { ReactNode,useState } from "react" 8 | import { Pagination } from '@material-ui/lab' 9 | 10 | const PaginationComponent:React.FC = (props) => { 11 | 12 | const { dataLength, layout } = props.args 13 | 14 | const [pages, setPages] = useState(1) 15 | 16 | 17 | 18 | const handlePageChange = (event:React.ChangeEvent, page:number) => { 19 | 20 | setPages(page) 21 | Streamlit.setComponentValue(page-1) 22 | console.log(page) 23 | } 24 | 25 | return ( 26 | 27 | ) 28 | } 29 | 30 | export default withStreamlitConnection(PaginationComponent) 31 | -------------------------------------------------------------------------------- /streamlit_pagination/frontend/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDOM from "react-dom" 3 | import PaginationComponent from "./PaginationComponent" 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ) 11 | -------------------------------------------------------------------------------- /streamlit_pagination/frontend/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /streamlit_pagination/frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "noEmit": true, 16 | "jsx": "react" 17 | }, 18 | "include": ["src"] 19 | } 20 | -------------------------------------------------------------------------------- /streamlit_pagination/style.css: -------------------------------------------------------------------------------- 1 | iframe{ 2 | height:100px; 3 | width:500px; 4 | } --------------------------------------------------------------------------------