├── .gitignore ├── Demo_Assets ├── bouncing_images.gif ├── cookie_manager.gif ├── stepper_bar_demo.gif └── tab_bar.gif ├── FUNDING.yml ├── LICENSE ├── MANIFEST.in ├── README.md ├── build.py ├── extra_streamlit_components ├── BouncingImage │ ├── __init__.py │ └── frontend │ │ ├── package.json │ │ ├── public │ │ ├── bootstrap.min.css │ │ └── index.html │ │ ├── src │ │ ├── BouncingImage.jsx │ │ ├── index.tsx │ │ └── react-app-env.d.ts │ │ └── tsconfig.json ├── CookieManager │ ├── __init__.py │ └── frontend │ │ ├── package.json │ │ ├── public │ │ ├── bootstrap.min.css │ │ └── index.html │ │ └── src │ │ ├── CookieManager.jsx │ │ ├── index.jsx │ │ └── react-app-env.d.js ├── Router │ └── __init__.py ├── StepperBar │ ├── __init__.py │ └── frontend │ │ ├── package.json │ │ ├── public │ │ ├── bootstrap.min.css │ │ └── index.html │ │ ├── src │ │ ├── StepperBar.jsx │ │ ├── index.tsx │ │ └── react-app-env.d.ts │ │ └── tsconfig.json ├── TabBar │ ├── __init__.py │ └── frontend │ │ ├── package.json │ │ ├── public │ │ ├── bootstrap.min.css │ │ └── index.html │ │ ├── src │ │ ├── TabBar.tsx │ │ ├── index.tsx │ │ └── react-app-env.d.ts │ │ └── tsconfig.json └── __init__.py ├── main.py ├── requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | 132 | .idea 133 | .idea/ 134 | package-lock.json 135 | .prettierrc 136 | extra_streamlit_components/setup.* 137 | build_and_upload_to_twine* 138 | extra_streamlit_components/*/frontend/node_modules/ 139 | extra_streamlit_components/*/frontend/build/ -------------------------------------------------------------------------------- /Demo_Assets/bouncing_images.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed-512/Extra-Streamlit-Components/629e8b634a6ee8d914ffe621075ea39d2721e46f/Demo_Assets/bouncing_images.gif -------------------------------------------------------------------------------- /Demo_Assets/cookie_manager.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed-512/Extra-Streamlit-Components/629e8b634a6ee8d914ffe621075ea39d2721e46f/Demo_Assets/cookie_manager.gif -------------------------------------------------------------------------------- /Demo_Assets/stepper_bar_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed-512/Extra-Streamlit-Components/629e8b634a6ee8d914ffe621075ea39d2721e46f/Demo_Assets/stepper_bar_demo.gif -------------------------------------------------------------------------------- /Demo_Assets/tab_bar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohamed-512/Extra-Streamlit-Components/629e8b634a6ee8d914ffe621075ea39d2721e46f/Demo_Assets/tab_bar.gif -------------------------------------------------------------------------------- /FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: Mohamed-512 4 | patreon: mohamed512 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include extra_streamlit_components/*/frontend/build * 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Extra-Streamlit-Components 2 | 3 | [![Downloads](https://static.pepy.tech/badge/extra-streamlit-components)](https://static.pepy.tech/badge/extra-streamlit-components) 4 | [![Downloads](https://static.pepy.tech/badge/extra-streamlit-components/month)](https://static.pepy.tech/badge/extra-streamlit-components/month) 5 | [![Downloads](https://static.pepy.tech/badge/extra-streamlit-components/week)](https://static.pepy.tech/badge/extra-streamlit-components/week) 6 | 7 | An all-in-one place, to find complex or just not available components by default on streamlit. 8 | 9 | _Explained in details in my book [Web Application Development with Streamlit](https://amzn.to/3RQZiEa)_ 10 | 11 | 12 | 13 | 14 | ## Components 15 | 16 | Firstly, add `import extra_streamlit_components as stx` 17 | 18 | - ### Router 19 | - Route to specific pages in Streamlit. This leverages the use of query parameters to make custom routes in your Streamlit application. For best experience, make sure to include the st.cache_resource function decorator while initializing the Router object. 20 | ```python 21 | @st.cache_resource(hash_funcs={"_thread.RLock": lambda _: None}) 22 | def init_router(): 23 | return stx.Router({"/home": home, "/landing": landing}) 24 | 25 | def home(): 26 | return st.write("This is a home page") 27 | 28 | def landing(): 29 | return st.write("This is the landing page") 30 | 31 | router = init_router() 32 | router.show_route_view() 33 | 34 | c1, c2, c3 = st.columns(3) 35 | 36 | with c1: 37 | st.header("Current route") 38 | current_route = router.get_url_route() 39 | st.write(f"{current_route}") 40 | with c2: 41 | st.header("Set route") 42 | new_route = st.text_input("route") 43 | if st.button("Route now!"): 44 | router.route(new_route) 45 | with c3: 46 | st.header("Session state") 47 | st.write(st.session_state) 48 | ``` 49 | 50 | - ### Cookie Manager 51 | A browser cookie store and manager. 52 | Built on [universal-cookie](https://www.npmjs.com/package/universal-cookie#setname-value-options) with the capability of using its options 53 | 54 | _**Security Note:** In shared domains such as share.streamlit.io, other web developers can have access to the cookies you set and the same goes for you. This is not to be treaded as security bug but a circumstance the developer need to be aware of._ 55 | 56 | ```python 57 | import datetime 58 | st.write("# Cookie Manager") 59 | 60 | @st.fragment 61 | def get_manager(): 62 | return stx.CookieManager() 63 | 64 | cookie_manager = get_manager() 65 | 66 | st.subheader("All Cookies:") 67 | cookies = cookie_manager.get_all() 68 | st.write(cookies) 69 | 70 | c1, c2, c3 = st.columns(3) 71 | 72 | with c1: 73 | st.subheader("Get Cookie:") 74 | cookie = st.text_input("Cookie", key="0") 75 | clicked = st.button("Get") 76 | if clicked: 77 | value = cookie_manager.get(cookie=cookie) 78 | st.write(value) 79 | with c2: 80 | st.subheader("Set Cookie:") 81 | cookie = st.text_input("Cookie", key="1") 82 | val = st.text_input("Value") 83 | if st.button("Add"): 84 | cookie_manager.set(cookie, val) # Expires in a day by default 85 | with c3: 86 | st.subheader("Delete Cookie:") 87 | cookie = st.text_input("Cookie", key="2") 88 | if st.button("Delete"): 89 | cookie_manager.delete(cookie) 90 | ``` 91 | 92 | ![](Demo_Assets/cookie_manager.gif) 93 | 94 | - ### TabBar 95 | Inspire from React's `ScrollMenu`, this component receives a list of `TabBarItemData`, and returns the `id` of the 96 | selected tab 97 | ```python 98 | chosen_id = stx.tab_bar(data=[ 99 | stx.TabBarItemData(id=1, title="ToDo", description="Tasks to take care of"), 100 | stx.TabBarItemData(id=2, title="Done", description="Tasks taken care of"), 101 | stx.TabBarItemData(id=3, title="Overdue", description="Tasks missed out"), 102 | ], default=1) 103 | st.info(f"{chosen_id=}") 104 | ``` 105 | 106 | ![](Demo_Assets/tab_bar.gif) 107 | 108 | - ### BouncingImage 109 | Probably not the best naming but this component, renders an image by its path or url, and animates by zooming in and 110 | out repetitively giving an illusion of a bounce. 111 | 112 | ```python 113 | image_url = "https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.svg" 114 | stx.bouncing_image(image_source=image_url, animate=True, animation_time=1500, height=200, width=600) 115 | ``` 116 | ![](Demo_Assets/bouncing_images.gif) 117 | 118 | - ### StepperBar 119 | A streamlit wrapper on MaterialUI's Stepper 120 | 121 | ```python 122 | val = stx.stepper_bar(steps=["Ready", "Get Set", "Go"]) 123 | st.info(f"Phase #{val}") 124 | ``` 125 | ![](Demo_Assets/stepper_bar_demo.gif) 126 | 127 | 128 | 129 | [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/mohamed512) 130 | -------------------------------------------------------------------------------- /build.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | modules = os.listdir("extra_streamlit_components") 4 | 5 | for module in modules: 6 | path = os.path.join("extra_streamlit_components", module, "frontend") 7 | if os.path.exists(path): 8 | print(f"Preparing {path}") 9 | os.system(f"cd {path} && npm i && npm run build") 10 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import streamlit.components.v1 as components 3 | 4 | from extra_streamlit_components import IS_RELEASE 5 | 6 | if IS_RELEASE: 7 | absolute_path = os.path.dirname(os.path.abspath(__file__)) 8 | build_path = os.path.join(absolute_path, "frontend/build") 9 | _component_func = components.declare_component("bouncing_image", path=build_path) 10 | else: 11 | _component_func = components.declare_component("bouncing_image", url="http://localhost:3001") 12 | 13 | 14 | def bouncing_image(image_source: str, animate: bool, animation_time: int, 15 | height: float, width: float): 16 | _component_func(image=image_source, animate=animate, animation_time=animation_time, 17 | height=height, width=width) 18 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bouncing_image", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.11.4", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.3.2", 9 | "@testing-library/user-event": "^7.1.2", 10 | "@types/jest": "^24.0.0", 11 | "@types/node": "^12.0.0", 12 | "@types/react": "^16.9.0", 13 | "@types/react-dom": "^16.9.0", 14 | "material-ui": "^0.20.2", 15 | "react": "^16.13.1", 16 | "react-dom": "^16.13.1", 17 | "react-horizontal-scrolling-menu": "^0.7.10", 18 | "react-scripts": "3.4.1", 19 | "streamlit-component-lib": "^1.2.0", 20 | "typescript": "~3.7.2" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": "react-app" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | }, 43 | "homepage": "." 44 | } 45 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Streamlit Component 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/frontend/src/BouncingImage.jsx: -------------------------------------------------------------------------------- 1 | import { 2 | Streamlit, 3 | StreamlitComponentBase, 4 | withStreamlitConnection, 5 | } from "streamlit-component-lib" 6 | import React from "react" 7 | 8 | import { withStyles, createStyles } from "@material-ui/core/styles" 9 | import Grow from "@material-ui/core/Grow" 10 | import CardMedia from "@material-ui/core/CardMedia" 11 | 12 | const styles = createStyles((theme) => ({ 13 | root: { 14 | height: 180, 15 | }, 16 | container: { 17 | display: "flex", 18 | }, 19 | paper: { 20 | margin: 1, 21 | }, 22 | svg: { 23 | width: 100, 24 | height: 100, 25 | }, 26 | polygon: { 27 | fill: "white", 28 | stroke: "red", 29 | strokeWidth: 1, 30 | }, 31 | })) 32 | 33 | class BouncingImage extends StreamlitComponentBase { 34 | state = { 35 | animationTimeRoundTrip: 1750, 36 | isAnimating: true, 37 | keepAnimating: false, 38 | } 39 | 40 | constructor(props) { 41 | super(props) 42 | } 43 | 44 | componentDidMount() { 45 | const { animation_time, animate } = this.props.args 46 | 47 | Streamlit.setComponentValue(animate) 48 | this.setState( 49 | () => ({ 50 | animationTimeRoundTrip: animation_time, 51 | keepAnimating: animate, 52 | }), 53 | () => 54 | setInterval( 55 | () => 56 | this.state.keepAnimating && 57 | this.setState( 58 | () => ({ 59 | isAnimating: 60 | !this.state.isAnimating && this.state.keepAnimating, 61 | }), 62 | () => Streamlit.setComponentValue(this.state.keepAnimating) 63 | ), 64 | this.state.animationTimeRoundTrip / 2 65 | ) 66 | ) 67 | } 68 | 69 | render = () => { 70 | const isAnimating = this.state.isAnimating 71 | let { 72 | classes, 73 | args: { image, height, width }, 74 | } = this.props 75 | 76 | return ( 77 |
78 |
79 | 86 | 87 | 88 |
89 |
90 | ) 91 | } 92 | } 93 | 94 | export default withStreamlitConnection(withStyles(styles)(BouncingImage)) 95 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/frontend/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDOM from "react-dom" 3 | import BouncingImage from "./BouncingImage.jsx" 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ) 11 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/frontend/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /extra_streamlit_components/BouncingImage/frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 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 | -------------------------------------------------------------------------------- /extra_streamlit_components/CookieManager/__init__.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import os 3 | from typing import Literal, Optional, Union, Dict 4 | 5 | import streamlit as st 6 | import streamlit.components.v1 as components 7 | from extra_streamlit_components import IS_RELEASE 8 | 9 | if IS_RELEASE: 10 | absolute_path = os.path.dirname(os.path.abspath(__file__)) 11 | build_path = os.path.join(absolute_path, "frontend/build") 12 | _component_func = components.declare_component("cookie_manager", path=build_path) 13 | else: 14 | _component_func = components.declare_component( 15 | "cookie_manager", url="http://localhost:3000" 16 | ) 17 | 18 | 19 | class CookieManager: 20 | def __init__(self, key="init"): 21 | self.cookie_manager = _component_func 22 | self.cookies = self.cookie_manager(method="getAll", key=key, default={}) 23 | 24 | def get(self, cookie: str): 25 | self._remove_extra_spacing() 26 | return self.cookies.get(cookie) 27 | 28 | def set( 29 | self, 30 | cookie: str, 31 | val: Union[str, int, float, bool], 32 | key: str = "set", 33 | path: str = "/", 34 | expires_at: Optional[datetime.datetime] = None, 35 | max_age: Optional[float] = None, 36 | domain: Optional[str] = None, 37 | secure: Optional[bool] = None, 38 | same_site: Union[bool, None, Literal["lax", "strict"]] = "strict", 39 | ): 40 | """Sets a cookie with the given name and value. 41 | 42 | Args: 43 | cookie: The name of the cookie to set. 44 | val: The value of the cookie. 45 | key: The key to use for the component. 46 | path: Cookie path. Use '/' as the path if you want your cookie to be accessible on all pages. 47 | expires_at: Absolute expiration date for the cookie. Defaults to 1 day from now. 48 | max_age: Relative max age of the cookie from when the client receives it in seconds. 49 | domain: Domain for the cookie (sub.domain.com or .allsubdomains.com) 50 | secure: Is only accessible through HTTPS? 51 | same_site: Strict or Lax enforcement. 52 | """ 53 | if cookie is None or cookie == "": 54 | return 55 | 56 | if expires_at is None: 57 | expires_at = datetime.datetime.now() + datetime.timedelta(days=1) 58 | 59 | self._remove_extra_spacing() 60 | expires = expires_at.isoformat() 61 | options = { 62 | "path": path, 63 | "expires": expires, 64 | "maxAge": max_age, 65 | "domain": domain, 66 | "secure": secure, 67 | "sameSite": same_site, 68 | } 69 | # Remove None's 70 | options = {k: v for k, v in options.items() if v is not None} 71 | self.cookie_manager( 72 | method="set", 73 | cookie=cookie, 74 | value=val, 75 | options=options, 76 | key=key, 77 | default=False, 78 | ) 79 | self.cookies[cookie] = val 80 | 81 | def batch_set( 82 | self, 83 | cookies: Dict[str, Union[str, int, float, bool]], 84 | path: str = "/", 85 | expires_at: Optional[datetime.datetime] = None, 86 | max_age: Optional[float] = None, 87 | domain: Optional[str] = None, 88 | secure: Optional[bool] = None, 89 | same_site: Union[bool, None, Literal["lax", "strict"]] = "strict", 90 | ): 91 | i = 0 92 | for cookie, val in cookies.items(): 93 | self.set( 94 | cookie, 95 | val, 96 | f"set_{i}", 97 | path, 98 | expires_at, 99 | max_age, 100 | domain, 101 | secure, 102 | same_site, 103 | ) 104 | i += 1 105 | 106 | def delete(self, cookie, key="delete"): 107 | if cookie is None or cookie == "": 108 | return 109 | self.cookie_manager(method="delete", cookie=cookie, key=key, default=False) 110 | 111 | del self.cookies[cookie] 112 | 113 | def get_all(self, key="get_all"): 114 | self._remove_extra_spacing() 115 | self.cookies = self.cookie_manager(method="getAll", key=key, default={}) 116 | return self.cookies 117 | 118 | def _remove_extra_spacing(self): 119 | st.markdown( 120 | """ 121 | 124 | """, 125 | unsafe_allow_html=True, 126 | ) 127 | -------------------------------------------------------------------------------- /extra_streamlit_components/CookieManager/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cookie_manager", 3 | "version": "0.1.1", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "@types/jest": "^24.0.0", 10 | "@types/node": "^12.0.0", 11 | "@types/react": "^16.9.0", 12 | "@types/react-dom": "^16.9.0", 13 | "nodemon": "^2.0.12", 14 | "react": "^16.14.0", 15 | "react-dom": "^16.13.1", 16 | "react-scripts": "^4.0.3", 17 | "streamlit-component-lib": "^1.3.0", 18 | "universal-cookie": "^6.1.0" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "homepage": "." 42 | } 43 | -------------------------------------------------------------------------------- /extra_streamlit_components/CookieManager/frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Streamlit Component 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /extra_streamlit_components/CookieManager/frontend/src/CookieManager.jsx: -------------------------------------------------------------------------------- 1 | import { 2 | Streamlit, 3 | ComponentProps, 4 | withStreamlitConnection, 5 | } from "streamlit-component-lib" 6 | import React, { useEffect, useMemo } from "react" 7 | 8 | import Cookies from "universal-cookie" 9 | 10 | let last_output = null 11 | const cookies = new Cookies() 12 | 13 | const CookieManager = (props: ComponentProps) => { 14 | const setCookie = (cookie, value, options) => { 15 | const converted_options = { 16 | expires: new Date(options.expires), 17 | } 18 | options = { ...options, ...converted_options } 19 | cookies.set(cookie, value, options) 20 | return true 21 | } 22 | 23 | const getCookie = (cookie) => { 24 | const value = cookies.get(cookie) 25 | return value 26 | } 27 | 28 | const deleteCookie = (cookie) => { 29 | cookies.remove(cookie, { path: "/", samesite: "strict" }) 30 | return true 31 | } 32 | 33 | const getAllCookies = () => { 34 | return cookies.getAll() 35 | } 36 | 37 | const { args } = props 38 | 39 | const method = args["method"] 40 | const cookie = args["cookie"] 41 | const value = args["value"] 42 | const options = args["options"] 43 | 44 | let output = null 45 | 46 | switch (method) { 47 | case "set": 48 | output = setCookie(cookie, value, options) 49 | break 50 | case "get": 51 | output = getCookie(cookie) 52 | break 53 | case "getAll": 54 | output = getAllCookies() 55 | break 56 | case "delete": 57 | output = deleteCookie(cookie) 58 | break 59 | default: 60 | break 61 | } 62 | 63 | if (output && JSON.stringify(last_output) !== JSON.stringify(output)) { 64 | last_output = output 65 | Streamlit.setComponentValue(output) 66 | Streamlit.setComponentReady() 67 | } 68 | 69 | useEffect(() => Streamlit.setFrameHeight()) 70 | return
71 | } 72 | 73 | export default withStreamlitConnection(CookieManager) 74 | -------------------------------------------------------------------------------- /extra_streamlit_components/CookieManager/frontend/src/index.jsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDOM from "react-dom" 3 | import CookieManager from "./CookieManager" 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ) 11 | -------------------------------------------------------------------------------- /extra_streamlit_components/CookieManager/frontend/src/react-app-env.d.js: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /extra_streamlit_components/Router/__init__.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from urllib.parse import unquote 3 | import time 4 | 5 | 6 | # from werkzeug.routing import Map, Rule, NotFound, RequestRedirect 7 | 8 | 9 | def does_support_session_state(): 10 | try: 11 | return st.session_state is not None 12 | except: 13 | return False 14 | 15 | 16 | class Router: 17 | def __init__(self, routes: dict, **kwargs): 18 | # self.tmp = Map([ 19 | # Rule('/', endpoint='root'), 20 | # Rule('/home', endpoint='home'), 21 | # Rule('/', endpoint='id'), 22 | # ]) 23 | 24 | self.routes = routes 25 | if "key" in kwargs: 26 | st.warning( 27 | "No need for a key for initialization," 28 | " this is not a rendered component." 29 | ) 30 | if not does_support_session_state(): 31 | raise Exception( 32 | "Streamlit installation doesn't support session state." 33 | " Session state needs to be available in the used Streamlit installation" 34 | ) 35 | 36 | def show_route_view(self): 37 | query_route = self.get_nav_query_param() 38 | sys_route = self.get_url_route() 39 | 40 | if sys_route is None and query_route is None: 41 | self.route("/") 42 | return 43 | elif sys_route is not None and query_route is not None: 44 | st.query_params["nav"] = sys_route 45 | st.session_state["stx_router_route"] = sys_route 46 | elif query_route is not None: 47 | self.route(query_route) 48 | return 49 | 50 | _callable = self.routes.get(sys_route) 51 | if callable(_callable): 52 | _callable() 53 | 54 | # match_route = f"{sys_route}" 55 | # x = self.tmp.bind("", path_info=match_route).match() 56 | 57 | def get_nav_query_param(self): 58 | url = st.query_params.get("nav") 59 | url = url[0] if type(url) == list else url 60 | route = unquote(url) if url is not None else url 61 | return route 62 | 63 | def get_url_route(self): 64 | if ( 65 | "stx_router_route" in st.session_state 66 | and st.session_state.stx_router_route is not None 67 | ): 68 | return st.session_state.stx_router_route 69 | 70 | route = self.get_nav_query_param() 71 | return route 72 | 73 | def route(self, new_route): 74 | if new_route[0] != "/": 75 | new_route = "/" + new_route 76 | st.session_state["stx_router_route"] = new_route 77 | st.query_params["nav"] = new_route 78 | time.sleep(0.1) # Needed for URL param refresh 79 | st.rerun() 80 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import streamlit.components.v1 as components 3 | from streamlit.components.v1.components import CustomComponent 4 | from typing import List 5 | 6 | from extra_streamlit_components import IS_RELEASE 7 | 8 | if IS_RELEASE: 9 | absolute_path = os.path.dirname(os.path.abspath(__file__)) 10 | build_path = os.path.join(absolute_path, "frontend/build") 11 | _component_func = components.declare_component("stepper_bar", path=build_path) 12 | else: 13 | _component_func = components.declare_component("stepper_bar", url="http://localhost:3000") 14 | 15 | 16 | def stepper_bar(steps: List[str], is_vertical: bool = False, lock_sequence: bool = True) -> CustomComponent: 17 | component_value = _component_func(steps=steps, is_vertical=is_vertical, lock_sequence=lock_sequence, default=0) 18 | return component_value 19 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stepper_bar", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.11.4", 7 | "@testing-library/jest-dom": "^4.2.4", 8 | "@testing-library/react": "^9.3.2", 9 | "@testing-library/user-event": "^7.1.2", 10 | "@types/jest": "^24.0.0", 11 | "@types/node": "^12.0.0", 12 | "@types/react": "^16.9.0", 13 | "@types/react-dom": "^16.9.0", 14 | "material-ui": "^0.20.2", 15 | "react": "^16.13.1", 16 | "react-dom": "^16.13.1", 17 | "react-horizontal-scrolling-menu": "^0.7.10", 18 | "react-scripts": "3.4.1", 19 | "streamlit-component-lib": "^1.2.0", 20 | "typescript": "~3.7.2" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": "react-app" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | }, 43 | "homepage": "." 44 | } 45 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Streamlit Component 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/frontend/src/StepperBar.jsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import { 3 | Streamlit, 4 | StreamlitComponentBase, 5 | withStreamlitConnection 6 | } from "streamlit-component-lib" 7 | 8 | import Step from "@material-ui/core/Step" 9 | import StepLabel from "@material-ui/core/StepLabel" 10 | import Stepper from "@material-ui/core/Stepper" 11 | import { createStyles, withStyles } from "@material-ui/core/styles" 12 | 13 | const styles = createStyles((theme) => ({ 14 | root: { 15 | width: "100%", 16 | backgroundColor: "transparent", 17 | }, 18 | icon: { 19 | color: "grey", 20 | cursor: "pointer", 21 | "&$activeIcon": { 22 | color: "var(--primary-color)", 23 | }, 24 | "&$completedIcon": { 25 | color: "var(--primary-color)", 26 | }, 27 | }, 28 | 29 | activeIcon: {}, 30 | completedIcon: {}, 31 | })) 32 | 33 | class StepperBar extends StreamlitComponentBase { 34 | state = { activeStep: 0, steps: [], lockSequence: true } 35 | 36 | componentDidMount() { 37 | this.setState((prev, state) => ({ 38 | steps: this.props.args.steps, 39 | activeStep: this.props.args.default, 40 | lockSequence: this.props.args.lock_sequence 41 | })) 42 | } 43 | 44 | onClick = (index) => { 45 | const { activeStep, lockSequence } = this.state 46 | 47 | if (lockSequence) { 48 | if (index == activeStep + 1) { 49 | this.setState( 50 | (prev, state) => ({ 51 | activeStep: activeStep + 1, 52 | }), 53 | () => Streamlit.setComponentValue(this.state.activeStep) 54 | ) 55 | } else if (index < activeStep) { 56 | this.setState( 57 | (prev, state) => ({ 58 | activeStep: index, 59 | }), 60 | () => Streamlit.setComponentValue(this.state.activeStep) 61 | ) 62 | } 63 | } else { 64 | this.setState( 65 | (prev, state) => ({ 66 | activeStep: index, 67 | }), 68 | () => Streamlit.setComponentValue(this.state.activeStep) 69 | ) 70 | } 71 | } 72 | 73 | getLabelStyle = (index) => { 74 | const { activeStep } = this.state 75 | const style = {} 76 | if (index == activeStep) { 77 | style.color = "var(--text-color)" 78 | style.fontStyle = "italic" 79 | } else if (index < activeStep) { 80 | style.color = "var(--text-color)" 81 | style.fontWeight = "bold" 82 | } else { 83 | style.color = "grey" 84 | } 85 | return style 86 | } 87 | 88 | render = () => { 89 | let { classes, args: { is_vertical } } = this.props 90 | 91 | const { activeStep } = this.state 92 | const steps = this.state.steps 93 | 94 | return ( 95 |
96 | 102 | {steps.map((label, index) => ( 103 | this.onClick(index)} > 104 | 114 |

{label}

115 |
116 |
117 | ))} 118 |
119 |
120 | ) 121 | } 122 | } 123 | 124 | export default withStreamlitConnection(withStyles(styles)(StepperBar)) 125 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/frontend/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDOM from "react-dom" 3 | import StepperBar from "./StepperBar.jsx" 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ) 11 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/frontend/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /extra_streamlit_components/StepperBar/frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 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 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import streamlit.components.v1 as components 3 | from dataclasses import dataclass 4 | from typing import List 5 | from extra_streamlit_components import IS_RELEASE 6 | 7 | if IS_RELEASE: 8 | absolute_path = os.path.dirname(os.path.abspath(__file__)) 9 | build_path = os.path.join(absolute_path, "frontend/build") 10 | _component_func = components.declare_component("tab_bar", path=build_path) 11 | else: 12 | _component_func = components.declare_component("tab_bar", url="http://localhost:3001") 13 | 14 | 15 | @dataclass(frozen=True, order=True, unsafe_hash=True) 16 | class TabBarItemData: 17 | id: int 18 | title: str 19 | description: str 20 | 21 | def to_dict(self): 22 | return {"id": self.id, "title": self.title, "description": self.description} 23 | 24 | 25 | def tab_bar(data: List[TabBarItemData], default=None, return_type=str, key=None): 26 | data = list(map(lambda item: item.to_dict(), data)) 27 | component_value = _component_func(data=data, selectedId=default, key=key, default=default) 28 | 29 | try: 30 | if return_type == str: 31 | return str(component_value) 32 | elif return_type == int: 33 | return int(component_value) 34 | elif return_type == float: 35 | return float(component_value) 36 | except: 37 | return component_value 38 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tab_bar", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.3.2", 8 | "@testing-library/user-event": "^7.1.2", 9 | "@types/jest": "^24.0.0", 10 | "@types/node": "^12.0.0", 11 | "@types/react": "^16.9.0", 12 | "@types/react-dom": "^16.9.0", 13 | "react": "^16.13.1", 14 | "react-dom": "^16.13.1", 15 | "react-horizontal-scrolling-menu": "^0.7.10", 16 | "react-scripts": "3.4.1", 17 | "streamlit-component-lib": "^1.2.0", 18 | "typescript": "~3.7.2" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "homepage": "." 42 | } 43 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Streamlit Component 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/frontend/src/TabBar.tsx: -------------------------------------------------------------------------------- 1 | import React, { ComponentProps, ReactNode } from "react" 2 | import ScrollMenu from "react-horizontal-scrolling-menu" 3 | import { 4 | Streamlit, 5 | StreamlitComponentBase, 6 | withStreamlitConnection 7 | } from "streamlit-component-lib" 8 | 9 | interface State { 10 | numClicks: number 11 | selectedId: number 12 | } 13 | 14 | interface MenuItem { 15 | id: number 16 | title: string 17 | description: string 18 | } 19 | 20 | class TabBar extends StreamlitComponentBase { 21 | public state = { numClicks: 0, selectedId: 1, list: [] } 22 | 23 | constructor(props: ComponentProps) { 24 | super(props) 25 | this.state.list = this.props.args["data"] 26 | this.state.selectedId = this.props.args["selectedId"] 27 | } 28 | 29 | MenuItem = ({ item, selectedId }: { item: MenuItem; selectedId: number }) => { 30 | 31 | return ( 32 |
33 |
{item.title}
34 |
35 | {item.description} 36 |
37 |
38 | ) 39 | } 40 | 41 | Menu(list: Array, selectedId: number) { 42 | return list.map((item) => ( 43 | 44 | )) 45 | } 46 | Arrow = ({ text, className }: { text: string; className: string }) => { 47 | return
{text}
48 | } 49 | 50 | ArrowLeft = this.Arrow({ text: "<", className: "arrow-prev" }) 51 | ArrowRight = this.Arrow({ text: ">", className: "arrow-next" }) 52 | 53 | public render = (): ReactNode => { 54 | return ( 55 |
56 | 64 |
69 |
70 | ) 71 | } 72 | 73 | onSelect = (id: any) => { 74 | this.setState( 75 | (state, props) => { 76 | return { selectedId: id } 77 | }, 78 | () => Streamlit.setComponentValue(id) 79 | ) 80 | } 81 | } 82 | 83 | export default withStreamlitConnection(TabBar) 84 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/frontend/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDOM from "react-dom" 3 | import TabBar from "./TabBar" 4 | 5 | ReactDOM.render( 6 | 7 | 8 | , 9 | document.getElementById("root") 10 | ) 11 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/frontend/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /extra_streamlit_components/TabBar/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 | -------------------------------------------------------------------------------- /extra_streamlit_components/__init__.py: -------------------------------------------------------------------------------- 1 | IS_RELEASE = True 2 | 3 | from .TabBar import tab_bar 4 | from .TabBar import TabBarItemData 5 | from .BouncingImage import bouncing_image 6 | from .StepperBar import stepper_bar 7 | from .CookieManager import CookieManager 8 | from .Router import Router 9 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import extra_streamlit_components as stx 3 | 4 | 5 | def show_router_controls(): 6 | @st.cache_resource(hash_funcs={"_thread.RLock": lambda _: None}) 7 | def init_router(): 8 | return stx.Router({"/home": home, "/landing": landing}) 9 | 10 | def home(): 11 | return st.write("This is a home page") 12 | 13 | def landing(): 14 | return st.write("This is the landing page") 15 | 16 | router = init_router() 17 | router.show_route_view() 18 | 19 | c1, c2, c3 = st.columns(3) 20 | 21 | with c1: 22 | st.header("Current route") 23 | current_route = router.get_url_route() 24 | st.write(f"{current_route}") 25 | with c2: 26 | st.header("Set route") 27 | new_route = st.text_input("route") 28 | if st.button("Route now!"): 29 | router.route(new_route) 30 | with c3: 31 | st.header("Session state") 32 | st.write(st.session_state) 33 | 34 | 35 | def show_cookie_manager_controls(): 36 | st.write("# Cookie Manager") 37 | 38 | @st.fragment 39 | def get_manager(): 40 | return stx.CookieManager() 41 | 42 | cookie_manager = get_manager() 43 | 44 | st.subheader("All Cookies:") 45 | cookies = cookie_manager.get_all() 46 | st.write(cookies) 47 | 48 | c1, c2, c3 = st.columns(3) 49 | 50 | with c1: 51 | st.subheader("Get Cookie:") 52 | cookie = st.text_input("Cookie", key="0") 53 | clicked = st.button("Get") 54 | if clicked: 55 | value = cookie_manager.get(cookie=cookie) 56 | st.write(value) 57 | with c2: 58 | st.subheader("Set Cookie:") 59 | cookie = st.text_input("Cookie", key="1") 60 | val = st.text_input("Value") 61 | if st.button("Add"): 62 | cookie_manager.set(cookie, val) # Expires in a day by default 63 | with c3: 64 | st.subheader("Delete Cookie:") 65 | cookie = st.text_input("Cookie", key="2") 66 | if st.button("Delete"): 67 | cookie_manager.delete(cookie) 68 | 69 | 70 | def show_bouncing_image(): 71 | st.write("# Bouncing Image") 72 | 73 | image_url = "https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.svg" 74 | stx.bouncing_image( 75 | image_source=image_url, animate=True, animation_time=2000, height=145, width=500 76 | ) 77 | 78 | st.code( 79 | """ 80 | image_url = "https://streamlit.io/images/brand/streamlit-logo-secondary-colormark-darktext.svg" 81 | stx.bouncing_image(image_source=image_url, animate=True, animation_time=2000, height=145, width=500) 82 | """ 83 | ) 84 | 85 | 86 | def show_top_bar(): 87 | st.write("# Tab Bar") 88 | 89 | chosen_id = stx.tab_bar( 90 | data=[ 91 | stx.TabBarItemData(id=1, title="ToDo", description="Tasks to take care of"), 92 | stx.TabBarItemData(id=2, title="Done", description="Tasks taken care of"), 93 | stx.TabBarItemData(id=3, title="Overdue", description="Tasks missed out"), 94 | ], 95 | default=1, 96 | return_type=int, 97 | ) 98 | 99 | st.info(f"chosen_id = {chosen_id}, type = {type(chosen_id)}") 100 | 101 | st.code( 102 | """ 103 | chosen_id = stx.tab_bar(data=[ 104 | stx.TabBarItemData(id=1, title="ToDo", description="Tasks to take care of"), 105 | stx.TabBarItemData(id=2, title="Done", description="Tasks taken care of"), 106 | stx.TabBarItemData(id=3, title="Overdue", description="Tasks missed out"), 107 | ], default=1) 108 | """ 109 | ) 110 | 111 | 112 | def show_stepper_bar(): 113 | st.write("# Stepper Bar") 114 | c1, c2, c3 = st.columns([1, 3, 1]) 115 | with c1: 116 | st.write("Horizontal") 117 | with c2: 118 | is_vertical = ( 119 | st.slider("Orientation", min_value=0, max_value=1, value=0) or 0 120 | ) == 1 121 | with c3: 122 | st.write("Vertical") 123 | 124 | is_sequence_locked = st.checkbox("Lock Sequence", value=True) 125 | 126 | if is_vertical: 127 | c1, c2 = st.columns([1, 3]) 128 | with c1: 129 | val = stx.stepper_bar( 130 | steps=["Ready", "Get Set", "Go"], 131 | is_vertical=is_vertical, 132 | lock_sequence=is_sequence_locked, 133 | ) 134 | with c2: 135 | st.info(f"Phase #{val}") 136 | else: 137 | val = stx.stepper_bar( 138 | steps=["Ready", "Get Set", "Go"], 139 | is_vertical=is_vertical, 140 | lock_sequence=is_sequence_locked, 141 | ) 142 | 143 | st.info(f"Phase #{val}") 144 | 145 | st.code( 146 | """ 147 | val = stx.stepper_bar(steps=["Ready", "Get Set", "Go"], is_vertical=False) 148 | """ 149 | ) 150 | 151 | 152 | if __name__ == "__main__": 153 | show_router_controls() 154 | st.write("_______") 155 | show_cookie_manager_controls() 156 | st.write("_______") 157 | show_top_bar() 158 | st.write("_______") 159 | show_bouncing_image() 160 | st.write("_______") 161 | show_stepper_bar() 162 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit>=1.40.1 2 | extra_streamlit_components~=0.1.80 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="extra_streamlit_components", 8 | version="0.1.80", 9 | author="Mohamed Abdou", 10 | author_email="matex512@gmail.com", 11 | description="An all-in-one place, to find complex or just natively unavailable components on streamlit.", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/Mohamed-512/Extra-Streamlit-Components", 15 | packages=setuptools.find_packages(), 16 | include_package_data=True, 17 | classifiers=[ 18 | "Programming Language :: Python :: 3", 19 | "License :: OSI Approved :: MIT License", 20 | "Operating System :: OS Independent", 21 | ], 22 | keywords=["Python", "Streamlit", "React", "JavaScript"], 23 | python_requires=">=3.6", 24 | install_requires=[ 25 | "streamlit >= 1.40.1", 26 | ], 27 | ) 28 | --------------------------------------------------------------------------------