├── .gitignore ├── LICENSE ├── README.md ├── component-logo.png ├── example.json ├── example.png ├── example.py ├── setup.py └── streamlit_timeline └── __init__.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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 innerdoc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![repo logo](https://github.com/innerdoc/streamlit-timeline/raw/main/component-logo.png) 2 | 3 | # Timeline Component for Streamlit 4 | 5 | A simple component to display a timeline in Streamlit apps. It integrates [Knightlab's TimelineJS](https://timeline.knightlab.com). 6 | 7 | 8 | ## Installation 9 | 10 | First install Streamlit (of course!) then pip-install this library: 11 | 12 | ```bash 13 | pip install streamlit 14 | pip install streamlit-timeline 15 | ``` 16 | 17 | 18 | ## Example 19 | 20 | ```python 21 | # Streamlit Timeline Component Example 22 | 23 | import streamlit as st 24 | from streamlit_timeline import timeline 25 | 26 | 27 | # use full page width 28 | st.set_page_config(page_title="Timeline Example", layout="wide") 29 | 30 | # load data 31 | with open('example.json', "r") as f: 32 | data = f.read() 33 | 34 | # render timeline 35 | timeline(data, height=800) 36 | ``` 37 | 38 | 39 | ## Parameters 40 | 41 | The `timeline()` function accepts a string or a dict, as long as it's in the [TimelineJS json format](https://timeline.knightlab.com/docs/json-format.html). The optional heigth of the visualization is in px. 42 | 43 | 44 | ## Preview 45 | You can also check the [preview video](https://www.youtube.com/embed/N61ed-XvPR4) or go to the demo [A History of Natural Language Processing](https://github.com/innerdoc/nlp-history-timeline). 46 | 47 | [![timeline example](https://github.com/innerdoc/streamlit-timeline/raw/main/example.png)](https://www.youtube.com/embed/N61ed-XvPR4) 48 | -------------------------------------------------------------------------------- /component-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innerdoc/streamlit-timeline/44a39d008b5c1c6dd0d03b332604aa8999e62272/component-logo.png -------------------------------------------------------------------------------- /example.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "title": { 4 | "media": { 5 | "url": "", 6 | "caption": " credits", 7 | "credit": "" 8 | }, 9 | "text": { 10 | "headline": "Welcome to
Streamlit Timeline", 11 | "text": "

A Streamlit Timeline component by integrating TimelineJS from Knightlab

" 12 | } 13 | }, 14 | "events": [ 15 | { 16 | "media": { 17 | "url": "https://vimeo.com/143407878", 18 | "caption": "How to Use TimelineJS (credits)" 19 | }, 20 | "start_date": { 21 | "year": "2016", 22 | "month":"1" 23 | }, 24 | "text": { 25 | "headline": "TimelineJS
Easy-to-make, beautiful timelines.", 26 | "text": "

TimelineJS is a populair tool from Knightlab. It has been used by more than 250,000 people to tell stories seen hundreds of millions of times, and is available in more than sixty languages.

" 27 | } 28 | }, 29 | { 30 | "media": { 31 | "url": "https://www.youtube.com/watch?v=CmSKVW1v0xM", 32 | "caption": "Streamlit Components (credits)" 33 | }, 34 | "start_date": { 35 | "year": "2020", 36 | "month":"7", 37 | "day":"13" 38 | }, 39 | "text": { 40 | "headline": "Streamlit Components
version 0.63.0", 41 | "text": "Streamlit lets you turn data scripts into sharable web apps in minutes, not weeks. It's all Python, open-source, and free! And once you've created an app you can use our free sharing platform to deploy, manage, and share your app with the world." 42 | } 43 | }, 44 | { 45 | "media": { 46 | "url": "https://github.com/innerdoc/streamlit-timeline/raw/main/component-logo.png", 47 | "caption": "github/innerdoc (credits)" 48 | }, 49 | "start_date": { 50 | "year": "2021", 51 | "month":"2" 52 | }, 53 | "text": { 54 | "headline": "Streamlit TimelineJS component", 55 | "text": "Started with a demo on https://www.innerdoc.com/nlp-timeline/ .
Then made a Streamlit component of it.
Then made a PyPi package for it." 56 | } 57 | } 58 | ] 59 | } -------------------------------------------------------------------------------- /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/innerdoc/streamlit-timeline/44a39d008b5c1c6dd0d03b332604aa8999e62272/example.png -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | # Streamlit Timeline Component Example 2 | 3 | import streamlit as st 4 | from streamlit_timeline import timeline 5 | 6 | 7 | # use full page width 8 | st.set_page_config(page_title="Timeline Example", layout="wide") 9 | 10 | # load data 11 | with open('example.json', "r") as f: 12 | data = f.read() 13 | 14 | # render timeline 15 | timeline(data, height=800) -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | 2 | from os.path import dirname 3 | from os.path import join 4 | import setuptools 5 | 6 | 7 | def readme() -> str: 8 | """Utility function to read the README file. 9 | Used for the long_description. It's nice, because now 1) we have a top 10 | level README file and 2) it's easier to type in the README file than to put 11 | a raw string in below. 12 | :return: content of README.md 13 | """ 14 | return open(join(dirname(__file__), "README.md")).read() 15 | 16 | 17 | setuptools.setup( 18 | name="streamlit-timeline", 19 | version="0.0.2", 20 | author="Rob van Zoest", 21 | author_email="", 22 | description="A Streamlit custom component to display a timeline", 23 | long_description=readme(), 24 | long_description_content_type="text/markdown", 25 | url="https://github.com/innerdoc/streamlit-timeline", 26 | project_urls={ 27 | "Github":"https://github.com/innerdoc/streamlit-timeline", 28 | "Homepage":"https://www.innerdoc.com", 29 | "Twitter":"https://twitter.com/innerdoc_nlp", 30 | }, 31 | packages=setuptools.find_packages(), 32 | include_package_data=True, 33 | classifiers=[ 34 | "Programming Language :: Python :: 3", 35 | "Operating System :: OS Independent", 36 | ], 37 | python_requires=">=3.6", 38 | install_requires=[ 39 | "streamlit >= 0.70", 40 | ], 41 | ) -------------------------------------------------------------------------------- /streamlit_timeline/__init__.py: -------------------------------------------------------------------------------- 1 | import json 2 | import streamlit.components.v1 as components 3 | 4 | 5 | def timeline(data, height=800): 6 | 7 | """Create a new timeline component. 8 | 9 | Parameters 10 | ---------- 11 | data: str or dict 12 | String or dict in the timeline json format: https://timeline.knightlab.com/docs/json-format.html 13 | height: int or None 14 | Height of the timeline in px 15 | 16 | Returns 17 | ------- 18 | static_component: Boolean 19 | Returns a static component with a timeline 20 | """ 21 | 22 | # if string then to json 23 | if isinstance(data, str): 24 | data = json.loads(data) 25 | 26 | # json to string 27 | json_text = json.dumps(data) 28 | 29 | # load json 30 | source_param = 'timeline_json' 31 | source_block = f'var {source_param} = {json_text};' 32 | 33 | # load css + js 34 | cdn_path = 'https://cdn.knightlab.com/libs/timeline3/latest' 35 | css_block = f'' 36 | js_block = f'' 37 | 38 | 39 | # write html block 40 | htmlcode = css_block + ''' 41 | ''' + js_block + ''' 42 | 43 |
44 | 45 | ''' 52 | 53 | 54 | # return rendered html 55 | static_component = components.html(htmlcode, height=height,) 56 | 57 | return static_component 58 | --------------------------------------------------------------------------------