├── .gitignore ├── INSTALL.md ├── LICENSE ├── Makefile ├── NEEDS.md ├── README.md ├── private ├── home.py ├── logout.py └── my_private_page.py ├── public ├── home.py ├── login.py └── my_public_page.py ├── requirements.txt └── streamlit_app.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 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Install requirements with a virtual environment 2 | 3 | ## Crear el ambiente 4 | virtualenv venv 5 | 6 | ## Activar ambiente 7 | source venv/bin/activate 8 | 9 | ## Instalar librerías 10 | pip install -r requirements.txt 11 | 12 | ## Desactivar Ambiente 13 | deactivate 14 | 15 | ## Borrar el ambiente 16 | rm -rf venv/ 17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Sebastian Flores 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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .ONESHELL: 2 | 3 | SHELL := /bin/bash 4 | 5 | activate: 6 | source venv/bin/activate; \ 7 | 8 | run: 9 | source venv/bin/activate 10 | streamlit run streamlit_app.py 11 | 12 | 13 | install: 14 | virtualenv venv 15 | source venv/bin/activate 16 | pip install -r requirements.txt 17 | deactivate 18 | 19 | 20 | make uninstall: 21 | rm -rf venv/ 22 | 23 | make clean: 24 | rm -rf tmp/ 25 | -------------------------------------------------------------------------------- /NEEDS.md: -------------------------------------------------------------------------------- 1 | ADD to template. 2 | 3 | Makefile: create env, delete, activate, run, etc. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Streamlit Template 2 | 3 | This is a template for streamlit projects. You can modify it at will. 4 | 5 | # Customize 6 | 7 | Edit `/streamlit_app.py`, `/public/*.py` and `/private/*.py` to customize this app. 8 | 9 | # Online demo 10 | 11 | To see an online demo, use this link: 12 | 13 | [https://stbook-template.streamlitapp.com/](https://stbook-template.streamlitapp.com/) 14 | 15 | ## Local run 16 | 17 | To locally run the app: 18 | 19 | ``` 20 | virtualenv venv 21 | source venv/bin/activate 22 | pip install -r requirements.txt 23 | streamlit run streamlit_app.py 24 | ``` 25 | 26 | ## Authentication 27 | 28 | Don't forget to add a `.streamlit/secrets.toml` with the desired credentials like this: 29 | 30 | ``` 31 | USER = "my_username" 32 | PASSWORD = "my_password" 33 | ``` 34 | 35 | (Or edit the settings on share.streamlit.io, if deployed there.) 36 | 37 | -------------------------------------------------------------------------------- /private/home.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import streamlit_book as stb 3 | 4 | st.title("Private Home") 5 | 6 | st.markdown(""" 7 | This is where you should put your **private** landing page. 8 | Just edit the file `private/home.py`. 9 | 10 | Maybe you put some considerations on the reason to have a private space. 11 | """) -------------------------------------------------------------------------------- /private/logout.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | 3 | st.title("Logout") 4 | 5 | st.markdown("Click to logout") 6 | 7 | def on_click(): 8 | import time 9 | st.session_state["admin_view"] = False 10 | st.success("Logged out") 11 | time.sleep(.25) 12 | query_dict = {} 13 | st.experimental_set_query_params(**query_dict) 14 | 15 | st.button("Logout", on_click=on_click) 16 | -------------------------------------------------------------------------------- /private/my_private_page.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import streamlit_book as stb 3 | import numpy as np 4 | import pandas as pd 5 | 6 | st.title("My Public Page") 7 | 8 | st.markdown("This is where you put your **private** content.") 9 | 10 | st.subheader("Maybe cat pictures") 11 | st.image("https://cataas.com/cat/cute") 12 | 13 | 14 | st.subheader("Maybe some data") 15 | st.markdown("Some data that you want to share with your collaborators but needs to remain private.") 16 | N = 5 17 | df = pd.DataFrame(100*np.random.randn(5, N), columns=('col%d' % i for i in range(N))) 18 | st.dataframe(df) # Same as st.write(df) 19 | -------------------------------------------------------------------------------- /public/home.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import streamlit_book as stb 3 | 4 | st.title("Home") 5 | 6 | st.markdown(""" 7 | This is where you should put your Home landing page. 8 | Just edit the file `public/home.py`. 9 | """) 10 | 11 | st.markdown(""" 12 | This streamlit multipage template allows to have public pages and private pages. 13 | * You can see it working at this link: https://stbook-template.streamlitapp.com/ 14 | * You can download it or fork it from this link: https://github.com/sebastiandres/template_streamlit_multipage 15 | * Edit the pages, create more pages and edit the content to suit your needs! 16 | """) 17 | 18 | st.markdown("---") 19 | st.subheader("Share the love!") 20 | stb.share("Look at this cool streamlit template I found!", "https://stbook-template.streamlitapp.com/") -------------------------------------------------------------------------------- /public/login.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | 3 | # Auxiliary functions for autentication 4 | def on_click(): 5 | import time 6 | if st.session_state["correct_password"]: 7 | st.session_state["admin_view"] = True 8 | time.sleep(.25) 9 | query_dict = {} 10 | st.experimental_set_query_params(**query_dict) 11 | else: 12 | st.warning("Wrong username or password") 13 | 14 | st.title("Login") 15 | c1, c2, c3 = st.columns([2,2,1]) 16 | user = c1.text_input("Username:", "") 17 | pswd = c2.text_input("Password:", "", type="password") 18 | 19 | try: 20 | USER = st.secrets["USER"] 21 | PASSWORD = st.secrets["PASSWORD"] 22 | if user==USER and pswd==PASSWORD: 23 | st.session_state["correct_password"] = True 24 | else: 25 | st.session_state["correct_password"] = False 26 | c3.markdown("") 27 | c3.markdown("") 28 | c3.button("Check", on_click=on_click) 29 | except Exception as e: 30 | st.exception(e) 31 | mkd = """Please set the user and password. Add 2 lines like this to your secrets.toml file (with a stronger configuration):\n 32 | USER = "admin"\n 33 | PASSWORD = "1234" 34 | """ 35 | st.error(mkd) 36 | 37 | st.markdown("---") 38 | st.markdown("This is an optional page. You can remove this page from streamlit_app.py, and the app will still work.") 39 | st.markdown("You can also access this page by appending '?view=admin' to the [URL](https://stbook-template.streamlitapp.com/?view=admin)") 40 | 41 | st.markdown("Use the following EXTREMELY WEAK credentials to login: **admin** / **4321**") 42 | st.markdown("""You should set up variables USER and PASSWORD on .streamlit/secrets.toml 43 | and/or the app properties (as suggested on 44 | [streamlit's secrets](https://docs.streamlit.io/streamlit-cloud/get-started/deploy-an-app/connect-to-data-sources/secrets-management) 45 | )""") 46 | -------------------------------------------------------------------------------- /public/my_public_page.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import streamlit_book as stb 3 | import numpy as np 4 | import pandas as pd 5 | 6 | st.title("My Public Page") 7 | 8 | st.markdown("This is where you put your public content. This file is 'public/my_public_page.py'.") 9 | 10 | st.markdown(""" 11 | * Copy and rename as many files as needed. 12 | * Edit streamlit_app.py to include the files as pages! 13 | """) 14 | 15 | st.subheader("Maybe some data") 16 | N = 10 17 | df = pd.DataFrame(100*np.random.randn(5, N), columns=('col%d' % i for i in range(N))) 18 | st.dataframe(df) # Same as st.write(df) 19 | 20 | st.subheader("Maybe some plots") 21 | chart_data = pd.DataFrame( 22 | np.random.randn(20, 3), 23 | columns=['a', 'b', 'c']) 24 | st.line_chart(chart_data) 25 | 26 | st.subheader("Maybe some interactive activities") 27 | stb.true_or_false( 28 | 'Is "Indiana Jones and the Last Crusade" the best movie of the trilogy?', 29 | True, 30 | success="You have chosen wisely", 31 | error="You have chosen poorly", 32 | button="You must choose" 33 | ) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | #streamlit_book 3 | git+https://github.com/sebastiandres/streamlit_book.git 4 | pandas 5 | numpy 6 | matplotlib -------------------------------------------------------------------------------- /streamlit_app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import streamlit_book as stb 3 | 4 | # Set wide display 5 | st.set_page_config(layout="wide") 6 | 7 | # Check if view is admin 8 | if "admin_view" in st.session_state: 9 | admin_view = st.session_state["admin_view"] 10 | else: 11 | admin_view = False 12 | 13 | # Check if query param 14 | query_params = st.experimental_get_query_params() 15 | if "view" in query_params: 16 | if query_params["view"][0] == "admin": 17 | stb.render_file("public/login.py") 18 | else: 19 | # Set private and public views 20 | if admin_view: 21 | stb.set_book_config( 22 | menu_title="Admin", 23 | menu_icon="public", 24 | options=[ 25 | "My Private Home", 26 | "A Private Page", 27 | "Logout", 28 | ], 29 | paths=[ 30 | "private/home.py", 31 | "private/my_private_page.py", 32 | "private/logout.py", 33 | ], 34 | save_answers=False, 35 | styles={ 36 | "nav-link": {"--hover-color": "#fde8ec"}, 37 | "nav-link-selected": {"background-color": "#DC143C"}, 38 | } 39 | ) 40 | else: 41 | stb.set_book_config( 42 | menu_title="Public View", 43 | menu_icon="private", 44 | options=[ 45 | "Home", 46 | "Some Interesting Page", 47 | "Login", 48 | ], 49 | paths=[ 50 | "public/home.py", 51 | "public/my_public_page.py", 52 | "public/login.py", 53 | ], 54 | save_answers=False, 55 | styles={ 56 | "nav-link": {"--hover-color": "#e9f6fb"}, 57 | "nav-link-selected": {"background-color": "#87CEEB"}, 58 | } 59 | ) 60 | 61 | # Add floating button 62 | stb.floating_button("https://sebastiandres.typeform.com/to/tlqGY1T9", "chat-left-dots-fill", "white", "red") --------------------------------------------------------------------------------