├── config
└── config.yaml
├── requirements.txt
├── setup.py
├── .gitignore
├── Home.py
├── src
└── Streamlit_Magic_Cheat_Sheets
│ └── README.md
├── research
└── magic_sheet.py
└── README.md
/config/config.yaml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | streamlit==1.29.0
2 | pathlib
3 | pybase64
4 | requests
5 | altair
6 | plotly
7 | bokeh==2.4.3
8 | pydeck
9 | graphviz
10 | scipy
11 | datetime
12 | pandas
13 | numpy
14 | -e.
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import setuptools
2 |
3 | with open("README.md", "r", encoding="utf-8") as f:
4 | long_description = f.read()
5 |
6 |
7 | __version__ = "1.0.0"
8 |
9 | REPO_NAME = "Streamlit_Magic_Cheat_Sheets"
10 | AUTHOR_USER_NAME = "tushar2704"
11 | SRC_REPO = "Streamlit-Magic-Cheat-Sheet"
12 | AUTHOR_EMAIL = "tushar.27041994@gmail.com"
13 |
14 |
15 | setuptools.setup(
16 | name=SRC_REPO,
17 | version=__version__,
18 | author=AUTHOR_USER_NAME,
19 | author_email=AUTHOR_EMAIL,
20 | description="Streamlit_Magic_Cheat_Sheets - ST App",
21 | long_description=long_description,
22 | long_description_content="text/markdown",
23 | url=f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}",
24 | project_urls={
25 | "Bug Tracker": f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}/issues",
26 | },
27 | package_dir={"": "src"},
28 | packages=setuptools.find_packages(where="src")
29 | )
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 |
5 | # C extensions
6 | *.so
7 |
8 | # Distribution / packaging
9 | .Python
10 | env/
11 | .venv
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg'
26 | venv
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | *.log
54 |
55 | # Sphinx documentation
56 | docs/_build/
57 |
58 | # PyBuilder
59 | target/
60 |
61 | # DotEnv configuration
62 | .env
63 |
64 | # Database
65 | *.db
66 | *.rdb
67 |
68 | # Pycharm
69 | .idea
70 |
71 | # VS Code
72 | .vscode/
73 |
74 | # Spyder
75 | .spyproject/
76 |
77 | # Jupyter NB Checkpoints
78 | .ipynb_checkpoints/
79 |
80 | # Mac OS-specific storage files
81 | .DS_Store
82 |
83 | # vim
84 | *.swp
85 | *.swo
86 |
87 | # Caches
88 | .mypy_cache/
89 | .pytest_cache/
90 | .ruff_cache/
91 |
92 | # Hydra logs
93 | outputs
94 | #Manual
95 | template.py
96 | templates/
97 | .streamlit/secrets.toml
98 | secrets.toml
--------------------------------------------------------------------------------
/Home.py:
--------------------------------------------------------------------------------
1 | ##© 2023 Tushar Aggarwal. All rights reserved.
2 | ##Streamlit Magic Cheat Sheets
3 | #######################################################################################################
4 | #Full length is above 10000 lines and is avalibale when you buy me a beer (https://www.buymeacoffee.com/taggdata)
5 |
6 | #######################################################################################################
7 | #Importind required libraries
8 | #######################################################################################################
9 | import streamlit as st
10 | from pathlib import Path
11 | import base64
12 | import sys
13 | from pathlib import Path
14 |
15 | import warnings
16 | warnings.filterwarnings("ignore")
17 | import os
18 | #######################################################################################################
19 | #Importing from SRC
20 | #######################################################################################################
21 |
22 | #######################################################################################################
23 | #Header of Streamlit Magic Cheat Sheets by github.com/tushar2704
24 | #######################################################################################################
25 | main_header()
26 | #######################################################################################################
27 | #Page Config of Streamlit Magic Cheat Sheets by github.com/tushar2704
28 | #######################################################################################################
29 | custom_style()
30 | #######################################################################################################
31 | #Body of Streamlit Magic Cheat Sheets by github.com/tushar2704
32 | #######################################################################################################
33 | left_main_panel()
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | footer()
42 | #######################################################################################################
43 | #End of Streamlit Magic Cheat Sheets by github.com/tushar2704
44 | #######################################################################################################
45 |
--------------------------------------------------------------------------------
/src/Streamlit_Magic_Cheat_Sheets/README.md:
--------------------------------------------------------------------------------
1 | # Streamlit Magic Cheat Sheets
2 |
3 |
4 |
5 |
6 | 
7 | 
8 | 
9 | 
10 | 
11 | 
12 | ## Deployment [](https://cheat-sheets.streamlit.app/)
13 |
14 | `Streamlit Magic Cheat Sheets` encapsulates the Streamlit documentation version 1.28.0, providing concise summaries along with exemplar implementations of Streamlit code snippets.
15 |
16 | **Version**`October, 2023 v1.1.1`
17 |
18 | The development and maintenance of this application are solely undertaken by [Tushar Aggarwal](https://www.linkedin.com/in/tusharaggarwalinseec/)
19 |
20 | 
21 | 
22 |
23 |
24 | ## Author
25 | - [©2023 Tushar Aggarwal. All rights reserved](https://www.tushar-aggarwal.com/)
26 | - [LinkedIn](https://www.linkedin.com/in/tusharaggarwalinseec/)
27 | - [Medium](https://medium.com/@tushar_aggarwal)
28 | - [Tushar-Aggarwal.com](https://www.tushar-aggarwal.com/)
29 | - [X](https://twitter.com/TaggData)
30 | - [Data Unboxed Newsletter](https://tadata.substack.com/)
31 | - [HuggingFace](https://huggingface.co/tushar27)
32 | - [DagsHub](https://dagshub.com/tushar27)
33 | - [Hashnode](https://hashnode.com/@TAGG)
34 | - [NovyPro](https://www.novypro.com/profile_projects/tusharagg)
35 | - [New Kaggle](https://www.kaggle.com/tagg27)
36 |
37 |
--------------------------------------------------------------------------------
/research/magic_sheet.py:
--------------------------------------------------------------------------------
1 | ##© 2023 Tushar Aggarwal. All rights reserved.
2 | ##Streamlit-Magic-Sheet
3 | #######################################################################################################
4 |
5 | #######################################################################################################
6 | #Importind required libraries
7 | #######################################################################################################
8 |
9 | import streamlit as st
10 | from pathlib import Path
11 | import base64
12 | import sys
13 | from pathlib import Path
14 | script_dir = Path(__file__).resolve().parent
15 | project_root = script_dir.parent
16 | sys.path.append(str(project_root))
17 | #######################################################################################################
18 | #Importing from SRC
19 | #######################################################################################################
20 | from src.Streamlit_Magic_Sheet.components.header import *
21 | from src.Streamlit_Magic_Sheet.components.body import *
22 | from src.Streamlit_Magic_Sheet.components.navigation import *
23 | from src.Streamlit_Magic_Sheet.components.siderbar import *
24 | from src.Streamlit_Magic_Sheet.components.metrics import *
25 | from src.Streamlit_Magic_Sheet.components.charts import *
26 | from src.Streamlit_Magic_Sheet.components.test import *
27 |
28 | #######################################################################################################
29 | #Research
30 | #######################################################################################################
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Streamlit Magical Cheat Sheets
2 |
3 |
4 |
5 |
6 | 
7 | 
8 | 
9 | 
10 | 
11 | 
12 | ## Deployment [](https://cheat-sheets.streamlit.app/)
13 |
14 | `Streamlit Magic Cheat Sheets` encapsulates the Streamlit documentation version 1.28.0, providing concise summaries along with exemplar implementations of Streamlit code snippets.
15 |
16 | **Version**`October, 2023 v1.1.1`
17 |
18 | The development and maintenance of this application are solely undertaken by [Tushar Aggarwal](https://www.linkedin.com/in/tusharaggarwalinseec/)
19 |
20 | 
21 |
22 | 
23 |
24 | ## Author
25 | - [©2023 Tushar Aggarwal. All rights reserved](https://www.tushar-aggarwal.com/)
26 | - [LinkedIn](https://www.linkedin.com/in/tusharaggarwalinseec/)
27 | - [Medium](https://medium.com/@tushar_aggarwal)
28 | - [Tushar-Aggarwal.com](https://www.tushar-aggarwal.com/)
29 | - [X](https://twitter.com/TaggData)
30 | - [Data Unboxed Newsletter](https://tadata.substack.com/)
31 | - [HuggingFace](https://huggingface.co/tushar27)
32 | - [DagsHub](https://dagshub.com/tushar27)
33 | - [Hashnode](https://hashnode.com/@TAGG)
34 | - [NovyPro](https://www.novypro.com/profile_projects/tusharagg)
35 | - [New Kaggle](https://www.kaggle.com/tagg27)
36 |
37 | ## Table of Contents
38 |
39 | 1. [Introduction to Streamlit](#introduction-to-streamlit)
40 | 2. [Getting Started with Streamlit](#getting-started-with-streamlit)
41 | - [Installation](#installation)
42 | - [Running a Streamlit App](#running-a-streamlit-app)
43 | - [Streamlit Hello World](#streamlit-hello-world)
44 | 3. [Streamlit Magic](#streamlit-magic)
45 | - [Streamlit Write](#streamlit-write)
46 | - [Streamlit Markdown](#streamlit-markdown)
47 | - [Streamlit Titles](#streamlit-titles)
48 | - [Streamlit Headers](#streamlit-headers)
49 | - [Streamlit Subheaders](#streamlit-subheaders)
50 | - [Streamlit Text](#streamlit-text)
51 | - [Streamlit Code](#streamlit-code)
52 | - [Streamlit LaTeX](#streamlit-latex)
53 | - [Streamlit JSON](#streamlit-json)
54 | 4. [Streamlit Widgets](#streamlit-widgets)
55 | - [Streamlit Button](#streamlit-button)
56 | - [Streamlit Checkbox](#streamlit-checkbox)
57 | - [Streamlit Radio](#streamlit-radio)
58 | - [Streamlit Selectbox](#streamlit-selectbox)
59 | - [Streamlit Multiselect](#streamlit-multiselect)
60 | - [Streamlit Slider](#streamlit-slider)
61 | - [Streamlit Text Input](#streamlit-text-input)
62 | - [Streamlit Text Area](#streamlit-text-area)
63 | - [Streamlit Date Input](#streamlit-date-input)
64 | - [Streamlit Time Input](#streamlit-time-input)
65 | - [Streamlit File Uploader](#streamlit-file-uploader)
66 | - [Streamlit Color Picker](#streamlit-color-picker)
67 | 5. [Streamlit Data Display](#streamlit-data-display)
68 | - [Streamlit Data Frame](#streamlit-data-frame)
69 | - [Streamlit Metric](#streamlit-metric)
70 | - [Streamlit JSON](#streamlit-json-1)
71 | - [Streamlit Table](#streamlit-table)
72 | 6. [Streamlit Charts](#streamlit-charts)
73 | - [Streamlit Line Chart](#streamlit-line-chart)
74 | - [Streamlit Area Chart](#streamlit-area-chart)
75 | - [Streamlit Bar Chart](#streamlit-bar-chart)
76 | - [Streamlit Pie Chart](#streamlit-pie-chart)
77 | - [Streamlit Altair Chart](#streamlit-altair-chart)
78 | - [Streamlit Plotly Chart](#streamlit-plotly-chart)
79 | - [Streamlit Bokeh Chart](#streamlit-bokeh-chart)
80 | - [Streamlit Deck GL Chart](#streamlit-deck-gl-chart)
81 | - [Streamlit Graphviz Chart](#streamlit-graphviz-chart)
82 | - [Streamlit Pyplot Chart](#streamlit-pyplot-chart)
83 | 7. [Streamlit Media](#streamlit-media)
84 | - [Streamlit Image](#streamlit-image)
85 | - [Streamlit Audio](#streamlit-audio)
86 | - [Streamlit Video](#streamlit-video)
87 | 8. [Streamlit Layout](#streamlit-layout)
88 | - [Streamlit Columns](#streamlit-columns)
89 | - [Streamlit Expander](#streamlit-expander)
90 | - [Streamlit Container](#streamlit-container)
91 | - [Streamlit Sidebar](#streamlit-sidebar)
92 | 9. [Streamlit State Management](#streamlit-state-management)
93 | - [Streamlit Session State](#streamlit-session-state)
94 | - [Streamlit State](#streamlit-state)
95 | 10. [Streamlit Caching](#streamlit-caching)
96 | - [Streamlit Memo](#streamlit-memo)
97 | - [Streamlit Cache Data](#streamlit-cache-data)
98 | - [Streamlit Cache Resource](#streamlit-cache-resource)
99 | 11. [Streamlit Theming](#streamlit-theming)
100 | - [Streamlit Config](#streamlit-config)
101 | - [Streamlit Themes](#streamlit-themes)
102 | 12. [Streamlit Deployment](#streamlit-deployment)
103 | - [Streamlit Sharing](#streamlit-sharing)
104 | - [Streamlit Cloud](#streamlit-cloud)
105 | - [Streamlit Heroku](#streamlit-heroku)
106 | - [Streamlit AWS](#streamlit-aws)
107 | - [Streamlit Azure](#streamlit-azure)
108 | - [Streamlit GCP](#streamlit-gcp)
109 | 13. [Streamlit Components](#streamlit-components)
110 | - [Streamlit Custom Components](#streamlit-custom-components)
111 | - [Streamlit Community Components](#streamlit-community-components)
112 | 14. [Streamlit Best Practices](#streamlit-best-practices)
113 | - [Streamlit Performance](#streamlit-performance)
114 | - [Streamlit Debugging](#streamlit-debugging)
115 | - [Streamlit Testing](#streamlit-testing)
116 | 15. [Streamlit Resources](#streamlit-resources)
117 | - [Streamlit Documentation](#streamlit-documentation)
118 | - [Streamlit Tutorials](#streamlit-tutorials)
119 | - [Streamlit Books](#streamlit-books)
120 | - [Streamlit Courses](#streamlit-courses)
121 | - [Streamlit Community](#streamlit-community)
122 | 16. [Streamlit Examples](#streamlit-examples)
123 | - [Streamlit Data Science Examples](#streamlit-data-science-examples)
124 | - [Streamlit Machine Learning Examples](#streamlit-machine-learning-examples)
125 | - [Streamlit NLP Examples](#streamlit-nlp-examples)
126 | - [Streamlit Computer Vision Examples](#streamlit-computer-vision-examples)
127 | - [Streamlit Recommender Systems Examples](#streamlit-recommender-systems-examples)
128 | - [Streamlit Finance Examples](#streamlit-finance-examples)
129 | - [Streamlit Healthcare Examples](#streamlit-healthcare-examples)
130 | - [Streamlit Retail Examples](#streamlit-retail-examples)
131 | - [Streamlit Cybersecurity Examples](#streamlit-cybersecurity-examples)
132 | - [Streamlit IoT Examples](#streamlit-iot-examples)
133 | 17. [Streamlit Alternatives](#streamlit-alternatives)
134 | - [Streamlit vs. Dash](#streamlit-vs-dash)
135 | - [Streamlit vs. Voila](#streamlit-vs-voila)
136 | - [Streamlit vs. Panel](#streamlit-vs-panel)
137 | - [Streamlit vs. Bokeh](#streamlit-vs-bokeh)
138 | - [Streamlit vs. Plotly Dash](#streamlit-vs-plotly-dash)
139 | 18. [Streamlit Integrations](#streamlit-integrations)
140 | - [Streamlit with Pandas](#streamlit-with-pandas)
141 | - [Streamlit with NumPy](#streamlit-with-numpy)
142 | - [Streamlit with Scikit-Learn](#streamlit-with-scikit-learn)
143 | - [Streamlit with TensorFlow](#streamlit-with-tensorflow)
144 | - [Streamlit with PyTorch](#streamlit-with-pytorch)
145 | - [Streamlit with Hugging Face](#streamlit-with-hugging-face)
146 | - [Streamlit with LangChain](#streamlit-with-langchain)
147 | - [Streamlit with OpenAI](#streamlit-with-openai)
148 | 19. [Streamlit Contributions](#streamlit-contributions)
149 | - [Streamlit GitHub](#streamlit-github)
150 | - [Streamlit Issues](#streamlit-issues)
151 | - [Streamlit Pull Requests](#streamlit-pull-requests)
152 | - [Streamlit Code of Conduct](#streamlit-code-of-conduct)
153 | 20. [Streamlit FAQ](#streamlit-faq)
154 | 21. [Streamlit Glossary](#streamlit-glossary)
155 | 22. [Streamlit Cheat Sheet](#streamlit-cheat-sheet)
156 | 23. [Streamlit Tips and Tricks](#streamlit-tips-and-tricks)
157 | 24. [Streamlit Roadmap](#streamlit-roadmap)
158 | 25. [Streamlit Changelog](#streamlit-changelog)
159 | 26. [Streamlit License](#streamlit-license)
160 | 27. [Streamlit Contributing](#streamlit-contributing)
161 | 28. [Streamlit Code of Conduct](#streamlit-code-of-conduct-1)
162 | 29. [Streamlit Security](#streamlit-security)
163 | 30. [Streamlit Feedback](#streamlit-feedback)
164 |
165 | ## Introduction to Streamlit
166 |
167 | Streamlit is an open-source Python library that allows you to create interactive web applications for data science and machine learning projects with minimal effort. It provides a simple and intuitive way to build user interfaces, visualize data, and deploy models without the need for extensive web development knowledge.
168 |
169 | Streamlit's main goal is to bridge the gap between data scientists and web development, enabling them to share their work and insights with others in a user-friendly and interactive manner. With Streamlit, you can create interactive dashboards, data explorers, and model visualizations using pure Python code.
170 |
171 | Some key features of Streamlit include:
172 |
173 | - **Easy to Learn**: Streamlit has a simple and intuitive API, making it easy for data scientists and developers to get started with building web applications.
174 | - **Interactive Widgets**: Streamlit provides a wide range of interactive widgets, such as sliders, dropdowns, and text inputs, allowing users to interact with your application and explore data.
175 | - **Data Visualization**: Streamlit supports various data visualization libraries, including Matplotlib, Plotly, Altair, and more, enabling you to create beautiful and interactive visualizations.
176 | - **Caching and State Management**: Streamlit provides built-in caching and state management capabilities, allowing you to create stateful applications and improve performance.
177 | - **Deployment**: Streamlit applications can be easily deployed to various platforms, including Streamlit Sharing, Heroku, AWS, and more.
178 |
179 | Streamlit has gained significant popularity in the data science and machine learning communities due to its simplicity and ease of use. It allows data scientists to focus on their core tasks, such as data analysis and model development, while providing a seamless way to share their work with others.
180 |
181 | ## Getting Started with Streamlit
182 |
183 | ### Installation
184 |
185 | To get started with Streamlit, you need to have Python installed on your system. You can install Streamlit using pip, the Python package installer:
186 |
187 | ```bash
188 | pip install streamlit
189 | ```
190 |
191 | Alternatively, you can install Streamlit in a virtual environment to keep your project dependencies isolated:
192 |
193 | ```bash
194 | python -m venv myenv
195 | source myenv/bin/activate # On Windows, use `myenv\Scripts\activate`
196 | pip install streamlit
197 | ```
198 |
199 | ### Running a Streamlit App
200 |
201 | To run a Streamlit app, create a Python file (e.g., `app.py`) and add your Streamlit code. Then, run the following command in your terminal or command prompt:
202 |
203 | ```bash
204 | streamlit run app.py
205 | ```
206 |
207 | This will start the Streamlit server and open your app in a new browser window.
208 |
209 | ### Streamlit Hello World
210 |
211 | Here's a simple "Hello, World!" example to get you started with Streamlit:
212 |
213 | ```python
214 | import streamlit as st
215 |
216 | st.title("Hello, World!")
217 | st.write("This is a Streamlit app.")
218 | ```
219 |
220 | When you run this code with `streamlit run app.py`, you should see a web page with the title "Hello, World!" and the text "This is a Streamlit app."
221 |
222 | ## Streamlit Magic
223 |
224 | Streamlit provides a variety of functions and widgets to create interactive web applications. Here are some of the most commonly used Streamlit features:
225 |
226 | ### Streamlit Write
227 |
228 | The `st.write()` function is used to display text, data, and other objects in your Streamlit app. It can handle various data types, including strings, numbers, Pandas DataFrames, and more.
229 |
230 | ```python
231 | import streamlit as st
232 |
233 | st.write("Hello, World!")
234 | st.write(42)
235 | st.write([1][2][3])
236 | ```
237 |
238 | ### Streamlit Markdown
239 |
240 | Streamlit supports Markdown formatting, allowing you to style your text with headings, lists, links, and more. You can use the `st.markdown()` function to render Markdown content.
241 |
242 | ```python
243 | import streamlit as st
244 |
245 | st.markdown("# This is a Heading")
246 | st.markdown("- This is a bullet point")
247 | st.markdown("[This is a link](https://streamlit.io/)")
248 | ```
249 |
250 | ### Streamlit Titles
251 |
252 | You can add titles to your Streamlit app using the `st.title()` function.
253 |
254 | ```python
255 | import streamlit as st
256 |
257 | st.title("My Streamlit App")
258 | ```
259 |
260 | ### Streamlit Headers
261 |
262 | Streamlit provides functions to add headers of different levels to your app.
263 |
264 | ```python
265 | import streamlit as st
266 |
267 | st.header("This is a Header")
268 | st.subheader("This is a Subheader")
269 | ```
270 |
271 | ### Streamlit Text
272 | ```python
273 | import streamlit as st
274 |
275 | st.text("This is some text.")
276 | ```
277 |
278 | ### Streamlit Code
279 |
280 | Streamlit allows you to display code snippets in your app using the `st.code()` function.
281 |
282 | ```python
283 | import streamlit as st
284 |
285 | code = """
286 | def hello():
287 | print("Hello, World!")
288 | """
289 |
290 | st.code(code, language="python")
291 | ```
292 |
293 | ### Streamlit LaTeX
294 |
295 | Streamlit supports rendering LaTeX equations using the `st.latex()` function.
296 |
297 | ```python
298 | import streamlit as st
299 |
300 | st.latex(r'''
301 | a + ar + a r^2 + a r^3 + \cdots + a r^n =
302 | \sum_{k=0}^n ar^k =
303 | a \left(\frac{1-r^{n+1}}{1-r}\right)
304 | ''')
305 | ```
306 |
307 | ### Streamlit JSON
308 |
309 | You can display JSON data in your Streamlit app using the `st.json()` function.
310 |
311 | ```python
312 | import streamlit as st
313 |
314 | data = {
315 | "name": "John Doe",
316 | "age": 30,
317 | "city": "New York"
318 | }
319 |
320 | st.json(data)
321 | ```
322 |
323 | ## Streamlit Widgets
324 |
325 | Streamlit provides a variety of interactive widgets that allow users to input data and control the behavior of your app.
326 |
327 | ### Streamlit Button
328 |
329 | The `st.button()` function creates a button that can be clicked to trigger an action.
330 |
331 | ```python
332 | import streamlit as st
333 |
334 | if st.button("Click me"):
335 | st.write("Button clicked!")
336 | ```
337 |
338 | ### Streamlit Checkbox
339 |
340 | The `st.checkbox()` function creates a checkbox that can be used to toggle a boolean value.
341 |
342 | ```python
343 | import streamlit as st
344 |
345 | agree = st.checkbox("I agree to the terms and conditions")
346 |
347 | if agree:
348 | st.write("Thank you for agreeing!")
349 | ```
350 |
351 | ### Streamlit Radio
352 |
353 | The `st.radio()` function creates a group of radio buttons, allowing the user to select one option from a list.
354 |
355 | ```python
356 | import streamlit as st
357 |
358 | option = st.radio(
359 | "Select an option",
360 | ("Option 1", "Option 2", "Option 3")
361 | )
362 |
363 | st.write(f"You selected: {option}")
364 | ```
365 |
366 | ### Streamlit Selectbox
367 |
368 | The `st.selectbox()` function creates a dropdown menu, allowing the user to select one option from a list.
369 |
370 | ```python
371 | import streamlit as st
372 |
373 | option = st.selectbox(
374 | "Select an option",
375 | ("Option 1", "Option 2", "Option 3")
376 | )
377 |
378 | st.write(f"You selected: {option}")
379 | ```
380 |
381 | ### Streamlit Multiselect
382 |
383 | The `st.multiselect()` function creates a multi-select widget, allowing the user to select multiple options from a list.
384 |
385 | ```python
386 | import streamlit as st
387 |
388 | options = st.multiselect(
389 | "Select options",
390 | ("Option 1", "Option 2", "Option 3")
391 | )
392 |
393 | st.write(f"You selected: {', '.join(options)}")
394 | ```
395 |
396 | ### Streamlit Slider
397 |
398 | The `st.slider()` function creates a slider widget, allowing the user to select a value within a specified range.
399 |
400 | ```python
401 | import streamlit as st
402 |
403 | value = st.slider("Select a value", 0, 100, 50)
404 |
405 | st.write(f"You selected: {value}")
406 | ```
407 |
408 | ### Streamlit Text Input
409 |
410 | The `st.text_input()` function creates a text input field, allowing the user to enter text.
411 |
412 | ```python
413 | import streamlit as st
414 |
415 | name = st.text_input("Enter your name", "Type here...")
416 |
417 | st.write(f"Hello, {name}!")
418 | ```
419 |
420 | ### Streamlit Text Area
421 |
422 | The `st.text_area()` function creates a multi-line text input area, allowing the user to enter longer text.
423 |
424 | ```python
425 | import streamlit as st
426 |
427 | message = st.text_area("Enter a message")
428 |
429 | st.write(f"You entered: {message}")
430 | ```
431 |
432 | ### Streamlit Date Input
433 |
434 | The `st.date_input()` function creates a date input widget, allowing the user to select a date.
435 |
436 | ```python
437 | import streamlit as st
438 |
439 | date = st.date_input("Select a date")
440 |
441 | st.write(f"You selected: {date}")
442 | ```
443 |
444 | ### Streamlit Time Input
445 |
446 | The `st.time_input()` function creates a time input widget, allowing the user to select a time.
447 |
448 | ```python
449 | import streamlit as st
450 |
451 | time = st.time_input("Select a time")
452 |
453 | st.write(f"You selected: {time}")
454 | ```
455 |
456 | ### Streamlit File Uploader
457 |
458 | The `st.file_uploader()` function creates a file uploader widget, allowing the user to upload files to your app.
459 |
460 | ```python
461 | import streamlit as st
462 |
463 | file = st.file_uploader("Upload a file")
464 |
465 | if file is not None:
466 | st.write(f"File name: {file.name}")
467 | st.write(f"File type: {file.type}")
468 | st.write(f"File size: {file.size} bytes")
469 | ```
470 |
471 | ### Streamlit Color Picker
472 |
473 | The `st.color_picker()` function creates a color picker widget, allowing the user to select a color.
474 |
475 | ```python
476 | import streamlit as st
477 |
478 | color = st.color_picker("Select a color")
479 |
480 | st.write(f"You selected: {color}")
481 | ```
482 |
483 | ## Streamlit Data Display
484 |
485 | Streamlit provides several functions to display data in your app, including DataFrames, metrics, JSON, and tables.
486 |
487 | ### Streamlit Data Frame
488 |
489 | The `st.dataframe()` function displays a Pandas DataFrame in your Streamlit app.
490 |
491 | ```python
492 | import streamlit as st
493 | import pandas as pd
494 |
495 | data = {
496 | "name": ["John", "Jane", "Bob"],
497 | "age": [25, 30, 35]
498 | }
499 |
500 | df = pd.DataFrame(data)
501 |
502 | st.dataframe(df)
503 | ```
504 |
505 | ### Streamlit Metric
506 |
507 | The `st.metric()` function displays a metric value with an optional label and optional delta value.
508 |
509 | ```python
510 | import streamlit as st
511 |
512 | st.metric("Temperature", "25°C", "1.2°C")
513 | ```
514 |
515 | ### Streamlit JSON
516 |
517 | The `st.json()` function displays JSON data in your Streamlit app.
518 |
519 | ```python
520 | import streamlit as st
521 |
522 | data = {
523 | "name": "John Doe",
524 | "age": 30,
525 | "city": "New York"
526 | }
527 |
528 | st.json(data)
529 | ```
530 |
531 | ### Streamlit Table
532 |
533 | The `st.table()` function displays a table in your Streamlit app.
534 |
535 | ```python
536 | import streamlit as st
537 | import pandas as pd
538 |
539 | data = {
540 | "name": ["John", "Jane", "Bob"],
541 | "age": [25, 30, 35]
542 | }
543 |
544 | df = pd.DataFrame(data)
545 |
546 | st.table(df)
547 | ```
548 |
549 | ## Streamlit Charts
550 |
551 | Streamlit supports various charting libraries, allowing you to create interactive visualizations in your app.
552 |
553 | ### Streamlit Line Chart
554 |
555 | The `st.line_chart()` function creates a line chart using Matplotlib or Altair.
556 |
557 | ```python
558 | import streamlit as st
559 | import pandas as pd
560 | import numpy as np
561 |
562 | chart_data = pd.DataFrame(
563 | np.random.randn(20, 3),
564 | columns=["a", "b", "c"]
565 | )
566 |
567 | st.line_chart(chart_data)
568 | ```
569 |
570 | ### Streamlit Area Chart
571 |
572 | The `st.area_chart()` function creates an area chart using Matplotlib or Altair.
573 |
574 | ```python
575 | import streamlit as st
576 | import pandas as pd
577 | import numpy as np
578 |
579 | chart_data = pd.DataFrame(
580 | np.random.randn(20, 3),
581 | columns=["a", "b", "c"]
582 | )
583 |
584 | st.area_chart(chart_data)
585 | ```
586 |
587 | ### Streamlit Bar Chart
588 |
589 | The `st.bar_chart()` function creates a bar chart using Matplotlib or Altair.
590 |
591 | ```python
592 | import streamlit as st
593 | import pandas as pd
594 | import numpy as np
595 |
596 | chart_data = pd.DataFrame(
597 | np.random.randn(5, 3), columns=["a", "b", "c"]
598 | )
599 |
600 | st.bar_chart(chart_data)
601 | ```
602 |
603 | ### Streamlit Pie Chart
604 |
605 | The `st.pie_chart()` function creates a pie chart using Matplotlib.
606 |
607 | ```python
608 | import streamlit as st
609 | import pandas as pd
610 |
611 | data = pd.DataFrame({
612 | "category": ["A", "B", "C"],
613 | "values": [30, 40, 30]
614 | })
615 |
616 | st.pie_chart(data["values"])
617 | ```
618 |
619 | ### Streamlit Altair Chart
620 |
621 | The `st.altair_chart()` function creates an Altair chart in your Streamlit app.
622 |
623 | ```python
624 | import streamlit as st
625 | import altair as alt
626 | import pandas as pd
627 |
628 | data = pd.DataFrame({
629 | "a": [1, 2, 3, 4, 5],
630 | "b": [1, 3, 2, 5, 4]
631 | })
632 |
633 | chart = alt.Chart(data).mark_line().encode(
634 | x="a",
635 | y="b"
636 | )
637 |
638 | st.altair_chart(chart, use_container_width=True)
639 | ```
640 |
641 | ### Streamlit Plotly Chart
642 |
643 | The `st.plotly_chart()` function creates a Plotly chart in your Streamlit app.
644 |
645 | ```python
646 | import streamlit as st
647 | import plotly.express as px
648 |
649 | df = px.data.iris()
650 | fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
651 |
652 | st.plotly_chart(fig)
653 | ```
654 |
655 | ### Streamlit Bokeh Chart
656 |
657 | The `st.bokeh_chart()` function creates a Bokeh chart in your Streamlit app.
658 |
659 | ```python
660 | import streamlit as st
661 | from bokeh.plotting import figure
662 |
663 | x = [1, 2, 3, 4, 5]
664 | y = [6, 7, 2, 4, 5]
665 |
666 | p = figure(
667 | title="Simple line example",
668 | x_axis_label="x",
669 | y_axis_label="y"
670 | )
671 |
672 | p.line(x, y, line_width=2)
673 |
674 | st.bokeh_chart(p, use_container_width=True)
675 | ```
676 |
677 | ### Streamlit Deck GL Chart
678 |
679 | The `st.deck_gl_chart()` function creates a Deck.gl chart in your Streamlit app.
680 |
681 | ```python
682 | import streamlit as st
683 | import pandas as pd
684 | import pydeck as pdk
685 |
686 | data = pd.DataFrame({
687 | "lat": [37.76, 37.77, 37.78],
688 | "lon": [-122.4, -122.41, -122.42]
689 | })
690 |
691 | layer = pdk.Layer(
692 | "HexagonLayer",
693 | data=data,
694 | get_position=["lon", "lat"],
695 | auto_highlight=True,
696 | elevation_scale=50,
697 | pickable=True,
698 | elevation_range=[0, 3000],
699 | extruded=True,
700 | )
701 |
702 | st.deck_gl_chart(
703 | viewport={
704 | "latitude": 37.76,
705 | "longitude": -122.4,
706 | "zoom": 11,
707 | "pitch": 50,
708 | },
709 | layers=[layer],
710 | )
711 | ```
712 |
713 | ### Streamlit Graphviz Chart
714 |
715 | The `st.graphviz_chart()` function creates a Graphviz chart in your Streamlit app.
716 |
717 | ```python
718 | import streamlit as st
719 | import graphviz as graphviz
720 |
721 | graph = graphviz.Digraph()
722 | graph.edge("run", "intr")
723 | graph.edge("intr", "kernel")
724 | graph.edge("kernel", "zombie")
725 | graph.edge("kernel", "sleep")
726 | graph.edge("kernel", "runnable")
727 | graph.edge("sleep", "runnable")
728 | graph.edge("runnable", "run")
729 | graph.edge("runnable", "kernel")
730 |
731 | st.graphviz_chart(graph)
732 | ```
733 |
734 | ### Streamlit Pyplot Chart
735 |
736 | The `st.pyplot()` function creates a Matplotlib chart in your Streamlit app.
737 |
738 | ```python
739 | import streamlit as st
740 | import matplotlib.pyplot as plt
741 | import numpy as np
742 |
743 | arr = np.random.normal(1, 1, size=100)
744 | fig, ax = plt.subplots()
745 | ax.hist(arr, bins=20)
746 |
747 | st.pyplot(fig)
748 | ```
749 |
750 | ## Streamlit Media
751 |
752 | Streamlit allows you to display various media types in your app, including images, audio, and video.
753 |
754 | ### Streamlit Image
755 |
756 | The `st.image()` function displays an image in your Streamlit app.
757 |
758 | ```python
759 | import streamlit as st
760 |
761 | st.image("https://example.com/image.jpg")
762 | ```
763 |
764 | ### Streamlit Audio
765 |
766 | The `st.audio()` function plays an audio file in your Streamlit app.
767 |
768 | ```python
769 | import streamlit as st
770 |
771 | st.audio("https://example.com/audio.mp3")
772 | ```
773 |
774 | ### Streamlit Video
775 |
776 | The `st.video()` function plays a video file in your Streamlit app.
777 |
778 | ```python
779 | import streamlit as st
780 |
781 | st.video("https://example.com/video.mp4")
782 | ```
783 |
784 | ## Streamlit Layout
785 |
786 | Streamlit provides several layout options to organize and structure your app's content.
787 |
788 | ### Streamlit Columns
789 |
790 | The `st.columns()` function creates multiple columns in your Streamlit app.
791 |
792 | ```python
793 | import streamlit as st
794 |
795 | col1, col2 = st.columns(2)
796 |
797 | with col1:
798 | st.write("Column 1")
799 |
800 | with col2:
801 | st.write("Column 2")
802 | ```
803 |
804 | ### Streamlit Expander
805 |
806 | The `st.expander()` function creates an expandable section in your Streamlit app.
807 |
808 | ```python
809 | import streamlit as st
810 |
811 | with st.expander("Click to expand"):
812 | st.write("This content is hidden by default.")
813 | ```
814 |
815 | ### Streamlit Container
816 |
817 | The `st.container()` function creates a container in your Streamlit app, allowing you to group elements together.
818 |
819 | ```python
820 | import streamlit as st
821 |
822 | with st.container():
823 | st.write("This content is inside a container.")
824 | ```
825 |
826 | ### Streamlit Sidebar
827 |
828 | The `st.sidebar` object allows you to create a sidebar in your Streamlit app.
829 |
830 | ```python
831 | import streamlit as st
832 |
833 | with st.sidebar:
834 | st.write("This content is in the sidebar.")
835 | ```
836 |
837 | ## Streamlit State Management
838 |
839 | Streamlit provides state management capabilities to handle user interactions and maintain application state.
840 |
841 | ### Streamlit Session State
842 |
843 | The `st.session_state` object allows you to store and retrieve data across multiple sessions.
844 |
845 | ```python
846 | import streamlit as st
847 |
848 | if "count" not in st.session_state:
849 | st.session_state.count = 0
850 |
851 | st.button("Increment", on_click=increment_count)
852 |
853 | def increment_count():
854 | st.session_state.count += 1
855 | st.write(f"Count: {st.session_state.count}")
856 | ```
857 |
858 | ### Streamlit State
859 |
860 | The `st.state` object allows you to store and retrieve data within the same session.
861 |
862 | ```python
863 | import streamlit as st
864 |
865 | if "count" not in st.state:
866 | st.state.count = 0
867 |
868 | st.button("Increment", on_click=increment_count)
869 |
870 | def increment_count():
871 | st.state.count += 1
872 | st.write(f"Count: {st.state.count}")
873 | ```
874 |
875 | ## Streamlit Caching
876 |
877 | Streamlit provides caching mechanisms to improve performance and reduce computation time.
878 |
879 | ### Streamlit Memo
880 |
881 | The `@st.memo` decorator caches the result of a function based on its input parameters.
882 |
883 | ```python
884 | import streamlit as st
885 |
886 | @st.memo
887 | def fibonacci(n):
888 | if n <= 1:
889 | return n
890 | else:
891 | return fibonacci(n-1) + fibonacci(n-2)
892 |
893 | n = st.number_input("Enter a number", value=10)
894 | result = fibonacci(n)
895 | st.write(f"The {n}th Fibonacci number is {result}")
896 | ```
897 |
898 | ### Streamlit Cache Data
899 |
900 | The `@st.cache_data` decorator caches the result of a function based on its input parameters and persists the cache across sessions.
901 |
902 | ```python
903 | import streamlit as st
904 | import pandas as pd
905 |
906 | @st.cache_data
907 | def load_data(path):
908 | return pd.read_csv(path)
909 |
910 | path = st.text_input("Enter the file path")
911 | data = load_data(path)
912 | st.write(data)
913 | ```
914 |
915 | ### Streamlit Cache Resource
916 |
917 | The `@st.cache_resource` decorator caches the result of a function and persists the cache across sessions, even if the function has no input parameters.
918 |
919 | ```python
920 | import streamlit as st
921 | import
922 | ```python
923 | import streamlit as st
924 | import requests
925 |
926 | @st.cache_resource
927 | def load_data():
928 | url = "https://example.com/data.csv"
929 | return pd.read_csv(requests.get(url).content)
930 |
931 | data = load_data()
932 | st.write(data)
933 | ```
934 |
935 | ## Streamlit Theming
936 |
937 | Streamlit allows you to customize the appearance of your app using themes and configuration settings.
938 |
939 | ### Streamlit Config
940 |
941 | The `st.set_page_config()` function allows you to set various configuration options for your Streamlit app, such as the page title, layout, and icon.
942 |
943 | ```python
944 | import streamlit as st
945 |
946 | st.set_page_config(
947 | page_title="My App",
948 | page_icon=":guardsman:",
949 | layout="wide",
950 | initial_sidebar_state="expanded"
951 | )
952 | ```
953 |
954 | ### Streamlit Themes
955 |
956 | Streamlit provides a built-in theming system that allows you to customize the appearance of your app using CSS.
957 |
958 | ```python
959 | import streamlit as st
960 |
961 | # Set the theme
962 | st.markdown(
963 | """
964 |
970 | """,
971 | unsafe_allow_html=True,
972 | )
973 | ```
974 |
975 | ## Streamlit Deployment
976 |
977 | Streamlit apps can be deployed to various platforms, including Streamlit Sharing, Heroku, AWS, Azure, and GCP.
978 |
979 | ### Streamlit Sharing
980 |
981 | Streamlit Sharing is a free hosting service provided by Streamlit that allows you to share your app with others.
982 |
983 | ```bash
984 | # Install the Streamlit Sharing CLI
985 | pip install streamlit-sharing
986 |
987 | # Deploy your app
988 | streamlit-sharing deploy app.py
989 | ```
990 |
991 | ### Streamlit Cloud
992 |
993 | Streamlit Cloud is a paid hosting service provided by Streamlit that offers additional features and scalability.
994 |
995 | ```bash
996 | # Install the Streamlit Cloud CLI
997 | pip install streamlit-cloud
998 |
999 | # Deploy your app
1000 | streamlit-cloud deploy app.py
1001 | ```
1002 |
1003 | ### Streamlit Heroku
1004 |
1005 | You can deploy your Streamlit app to Heroku, a cloud platform for hosting web applications.
1006 |
1007 | ```bash
1008 | # Create a new Heroku app
1009 | heroku create my-streamlit-app
1010 |
1011 | # Deploy your app
1012 | git push heroku master
1013 | ```
1014 |
1015 | ### Streamlit AWS
1016 |
1017 | You can deploy your Streamlit app to AWS using various services, such as Elastic Beanstalk, EC2, or ECS.
1018 |
1019 | ```bash
1020 | # Deploy your app to AWS Elastic Beanstalk
1021 | eb init
1022 | eb create my-streamlit-app
1023 | eb deploy
1024 | ```
1025 |
1026 | ### Streamlit Azure
1027 |
1028 | You can deploy your Streamlit app to Azure using various services, such as App Service or Azure Container Instances.
1029 |
1030 | ```bash
1031 | # Deploy your app to Azure App Service
1032 | az webapp up --name my-streamlit-app
1033 | ```
1034 |
1035 | ### Streamlit GCP
1036 |
1037 | You can deploy your Streamlit app to Google Cloud Platform (GCP) using various services, such as App Engine or Cloud Run.
1038 |
1039 | ```bash
1040 | # Deploy your app to GCP App Engine
1041 | gcloud app deploy
1042 | ```
1043 |
1044 | ## Streamlit Components
1045 |
1046 | Streamlit supports custom components and community-contributed components, allowing you to extend the functionality of your app.
1047 |
1048 | ### Streamlit Custom Components
1049 |
1050 | You can create custom Streamlit components using the Streamlit Components API.
1051 |
1052 | ```python
1053 | import streamlit.components.v1 as components
1054 |
1055 | # Create a custom component
1056 | my_component = components.declare_component("my_component", path="path/to/component")
1057 |
1058 | # Use the custom component in your app
1059 | my_value = my_component(default=0)
1060 | st.write(f"Value: {my_value}")
1061 | ```
1062 |
1063 | ### Streamlit Community Components
1064 |
1065 | Streamlit provides a repository of community-contributed components that you can install and use in your app.
1066 |
1067 | ```bash
1068 | # Install a community component
1069 | pip install streamlit-component-name
1070 |
1071 | # Use the community component in your app
1072 | import streamlit_component_name
1073 | ```
1074 |
1075 | ## Streamlit Best Practices
1076 |
1077 | To ensure the best performance, maintainability, and user experience for your Streamlit app, it's essential to follow best practices.
1078 |
1079 | ### Streamlit Performance
1080 |
1081 | Streamlit provides several techniques to optimize the performance of your app, such as caching, lazy evaluation, and state management.
1082 |
1083 | ```python
1084 | import streamlit as st
1085 |
1086 | # Use caching to avoid redundant computations
1087 | @st.cache_data
1088 | def expensive_computation(data):
1089 | # ...
1090 | return result
1091 |
1092 | # Use lazy evaluation to avoid unnecessary computations
1093 | if st.checkbox("Run computation"):
1094 | result = expensive_computation(data)
1095 | st.write(result)
1096 | ```
1097 |
1098 | ### Streamlit Debugging
1099 |
1100 | Streamlit provides various debugging tools and techniques to help you identify and fix issues in your app.
1101 |
1102 | ```python
1103 | import streamlit as st
1104 |
1105 | # Use the st.write() function to print debug information
1106 | st.write(f"Debug: {variable_value}")
1107 |
1108 | # Use the st.stop() function to stop execution at a specific point
1109 | if condition:
1110 | st.stop()
1111 | ```
1112 |
1113 | ### Streamlit Testing
1114 |
1115 | Streamlit supports testing your app using various testing frameworks, such as pytest and unittest.
1116 |
1117 | ```python
1118 | import streamlit as st
1119 | import pytest
1120 |
1121 | def test_app():
1122 | # Create a test instance of the Streamlit app
1123 | st.start_test_mode()
1124 |
1125 | # Run the app and perform assertions
1126 | assert st.button("Click me") == False
1127 | st.button("Click me")
1128 | assert st.button("Click me") == True
1129 |
1130 | # Stop the test mode
1131 | st.stop_test_mode()
1132 | ```
1133 |
1134 | ## Streamlit Resources
1135 |
1136 | Streamlit provides various resources to help you learn and develop with the library, including documentation, tutorials, books, courses, and a community.
1137 |
1138 | ### Streamlit Documentation
1139 |
1140 | The official Streamlit documentation is a comprehensive resource that covers all aspects of the library, including installation, usage, and advanced topics.
1141 |
1142 | - [Streamlit Documentation](https://docs.streamlit.io/)
1143 |
1144 | ### Streamlit Tutorials
1145 |
1146 | Streamlit provides a collection of tutorials that cover various topics and use cases, helping you get started and learn by example.
1147 |
1148 | - [Streamlit Tutorials](https://docs.streamlit.io/en/latest/tutorial/index.html)
1149 |
1150 | ### Streamlit Books
1151 |
1152 | Several books have been written on Streamlit, covering topics such as data visualization, machine learning, and web development.
1153 |
1154 | - "Streamlit for Data Science" by Sharone Zitzman
1155 | - "Streamlit for Data Visualization" by Brock Mendel
1156 |
1157 | ### Streamlit Courses
1158 |
1159 | Online courses are available to help you learn Streamlit and build applications for data science and machine learning.
1160 |
1161 | - "Streamlit for Data Science" on Coursera
1162 | - "Streamlit for Data Visualization" on Udemy
1163 |
1164 | ### Streamlit Community
1165 |
1166 | Streamlit has an active community of developers and users who contribute to the library, share resources, and provide support.
1167 |
1168 | - [Streamlit Community Forum](https://discuss.streamlit.io/)
1169 | - [Streamlit GitHub Repository](https://github.com/streamlit/streamlit)
1170 |
1171 | ## Streamlit Examples
1172 |
1173 | Streamlit provides a variety of examples to help you get started and learn by example.
1174 |
1175 | ### Streamlit Data Science Examples
1176 |
1177 | - [Data Exploration App](https://docs.streamlit.io/en/latest/tutorial/data_exploration.html)
1178 | - [Interactive Data Visualization](https://docs.streamlit.io/en/latest/tutorial/interactive_data_viz.html)
1179 | - [Machine Learning Model Deployment](https://docs.streamlit.io/en/latest/tutorial/model_deployment.html)
1180 |
1181 | ### Streamlit Machine Learning Examples
1182 |
1183 | - [Image Classification App](https://docs.streamlit.io/en/latest/tutorial/image_classification.html)
1184 | - [Natural Language Processing App](https://docs.streamlit.io/en/latest/tutorial/nlp_app.html)
1185 | - [Recommender System App](https://docs.streamlit.io/en/latest/tutorial/recommender_system.html)
1186 |
1187 | ### Streamlit NLP Examples
1188 |
1189 | - [Sentiment Analysis App](https://docs.streamlit.io/en/latest/tutorial/sentiment_analysis.html)
1190 | - [Text Generation App](https://docs.streamlit.io/en/latest/tutorial/text_generation.html)
1191 | - [Named Entity Recognition App](https://docs.streamlit.io/en/latest/tutorial/ner_app.html)
1192 |
1193 | ### Streamlit Computer Vision Examples
1194 |
1195 | - [Object Detection App](https://docs.streamlit.io/en/latest/tutorial/object_detection.html)
1196 | - [Image Segmentation App](https://docs.streamlit.io/en/latest/tutorial/image_segmentation.html)
1197 | - [Face Recognition App](https://docs.streamlit.io/en/latest/tutorial/face_recognition.html)
1198 |
1199 | ### Streamlit Recommender Systems Examples
1200 |
1201 | - [Movie Recommender App](https://docs.streamlit.io/en/latest/tutorial/movie_recommender.html)
1202 | - [Product Recommender App](https://docs.streamlit.io/en/latest/tutorial/product_recommender.html)
1203 | - [Music Recommender App](https://docs.streamlit.io/en/latest/tutorial/music_recommender.html)
1204 |
1205 | ### Streamlit Finance Examples
1206 |
1207 | - [Stock Price Prediction App](https://docs.streamlit.io/en/latest/tutorial/stock_prediction.html)
1208 | - [Portfolio Optimization App](https://docs.streamlit.io/en/latest/tutorial/portfolio_optimization.html)
1209 | - [Cryptocurrency Trading App](https://docs.streamlit.io/en/latest/tutorial/crypto_trading.html)
1210 |
1211 | ### Streamlit Healthcare Examples
1212 |
1213 | - [Patient Monitoring Dashboard](https://docs.streamlit.io/en/latest/tutorial/patient_monitoring.html)
1214 | - [Drug Discovery App](https://docs.streamlit.io/en/latest/tutorial/drug_discovery.html)
1215 | - [Medical Image Analysis App](https://docs.streamlit.io/en/latest/tutorial/medical_imaging.html)
1216 |
1217 | ### Streamlit Retail Examples
1218 |
1219 | - [Customer Segmentation App](https://docs.streamlit.io/en/latest/tutorial/customer_segmentation.html)
1220 | - [Product Recommendation App](https://docs.streamlit.io/en/latest/tutorial/product_recommendation.html)
1221 | - [Sales Forecasting App](https://docs.streamlit.io/en/latest/tutorial/sales_forecasting.html)
1222 |
1223 | ### Streamlit Cybersecurity Examples
1224 |
1225 | - [Network Traffic Monitoring App](https://docs.streamlit.io/en/latest/tutorial/network_monitoring.html)
1226 | - [Malware Detection App](https://docs.streamlit.io/en/latest/tutorial/malware_detection.html)
1227 | - [Vulnerability Scanning App](https://docs.streamlit.io/en/latest/tutorial/vulnerability_scanning.html)
1228 |
1229 | ### Streamlit IoT Examples
1230 |
1231 | - [Smart Home Monitoring App](https://docs.streamlit.io/en/latest/tutorial/smart_home.html)
1232 | - [Industrial Automation Dashboard](https://docs.streamlit.io/en/latest/tutorial/industrial_automation.html)
1233 | - [Environmental Monitoring App](https://docs.streamlit.io/en/latest/tutorial/environmental_monitoring.html)
1234 |
1235 | ## Streamlit Alternatives
1236 |
1237 | While Streamlit is a popular choice for building data science and machine learning applications, there are several alternatives available. Here are some of the most notable ones:
1238 |
1239 | ### Streamlit vs. Dash
1240 |
1241 | Dash is an open-source Python library for building analytical web applications, similar to Streamlit. It is built on top of Flask, React.js, and Plotly.js. Dash provides a more low-level and flexible approach compared to Streamlit, but it may require more web development knowledge.
1242 |
1243 | ### Streamlit vs. Voila
1244 |
1245 | Voila is a Python library that allows you to convert Jupyter Notebooks into interactive web applications. It provides a simple way to share and visualize data and models without writing additional code. Voila is a good choice if you primarily work with Jupyter Notebooks and want to share your work with others.
1246 |
1247 | ### Streamlit vs. Panel
1248 |
1249 | Panel is a Python library for building analytical web applications, similar to Streamlit and Dash. It is built on top of Bokeh, a library for creating interactive visualizations in the browser. Panel provides a more low-level and flexible approach compared to Streamlit, but it may require more web development knowledge.
1250 |
1251 | ### Streamlit vs. Bokeh
1252 |
1253 | Bokeh is a Python library for creating interactive visualizations in the browser. While Bokeh is primarily focused on data visualization, it can also be used to build web applications. Bokeh provides a more low-level and flexible approach compared to Streamlit, but it may require more web development knowledge.
1254 |
1255 | ### Streamlit vs. Plotly Dash
1256 |
1257 | Plotly Dash is a Python library for building analytical web applications, similar to Streamlit. It is built on top of Flask, React.js, and Plotly.js. Plotly Dash provides a more low-level and flexible approach compared to Streamlit, but it may require more web development knowledge.
1258 |
1259 | ## Streamlit Integrations
1260 |
1261 | Streamlit can be integrated with various Python libraries and frameworks to enhance its functionality and capabilities.
1262 |
1263 | ### Streamlit with Pandas
1264 |
1265 | Streamlit integrates seamlessly with Pandas, a popular Python library for data manipulation and analysis. You can display Pandas DataFrames, perform data transformations, and create interactive visualizations using Streamlit's built-in functions.
1266 |
1267 | ```python
1268 | import streamlit as st
1269 | import pandas as pd
1270 |
1271 | data = pd.read_csv("data.csv")
1272 | st.dataframe(data)
1273 | ```
1274 |
1275 | ### Streamlit with NumPy
1276 |
1277 | Streamlit can be used in conjunction with NumPy, a fundamental Python library for scientific computing. You can perform numerical operations, create arrays, and visualize data using Streamlit's charting capabilities.
1278 |
1279 | ```python
1280 | import streamlit as st
1281 | import numpy as np
1282 |
1283 | arr = np.random.randn(100)
1284 | st.line_chart(arr)
1285 | ```
1286 |
1287 | ### Streamlit with Scikit-Learn
1288 |
1289 | Streamlit can be integrated with Scikit-Learn, a popular Python library for machine learning. You can build and deploy machine learning models, visualize model performance, and create interactive interfaces for model tuning and evaluation.
1290 |
1291 | ```python
1292 | import streamlit as st
1293 | from sklearn.linear_model import LogisticRegression
1294 | from sklearn.datasets import load_iris
1295 |
1296 | iris = load_iris()
1297 | X, y = iris.data, iris.target
1298 |
1299 | model = LogisticRegression()
1300 | model.fit(X, y)
1301 |
1302 | st.write(f"Accuracy: {model.score(X, y):.2f}")
1303 | ```
1304 |
1305 | ### Streamlit with TensorFlow
1306 |
1307 | Streamlit can be used with TensorFlow, a popular open-source library for machine learning and deep learning. You can build and deploy TensorFlow models, visualize model performance, and create interactive interfaces for model tuning and evaluation.
1308 |
1309 | ```python
1310 | import streamlit as st
1311 | import tensorflow as tf
1312 |
1313 | # Load and preprocess data
1314 | (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
1315 |
1316 | # Build and train the model
1317 | model = tf.keras.models.Sequential([
1318 | tf.keras.layers.Flatten(input_shape=(28, 28)),
1319 | tf.keras.layers.Dense(128, activation='relu'),
1320 | tf.keras.layers.Dropout(0.2),
1321 | tf.keras.layers.Dense(10, activation='softmax')
1322 | ])
1323 |
1324 | model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
1325 | model.fit(x_train, y_train, epochs=5)
1326 |
1327 | # Evaluate the model
1328 | loss, accuracy = model.evaluate(x_test, y_test)
1329 | st.write(f"Accuracy: {accuracy:.2f}")
1330 | ```
1331 |
1332 | ### Streamlit with PyTorch
1333 |
1334 | Streamlit can be integrated with PyTorch, a popular open-source machine learning library. You can build and deploy PyTorch models, visualize model performance, and create interactive interfaces for model tuning and evaluation.
1335 |
1336 | ```python
1337 | import streamlit as st
1338 | import torch
1339 | import torchvision
1340 | import torchvision.transforms as transforms
1341 |
1342 | # Load and preprocess data
1343 | transform = transforms.Compose([
1344 | transforms.ToTensor(),
1345 | transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
1346 | ])
1347 |
1348 | trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)
1349 | trainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)
1350 |
1351 | # Build and train the model
1352 | net = torchvision.models.resnet18(pretrained=False)
1353 | criterion = torch.nn.CrossEntropyLoss()
1354 | optimizer = torch.optim.SGD(net.parameters(), lr=0.001, momentum=0.9)
1355 |
1356 | for epoch in range(2): # loop over the dataset multiple times
1357 |
1358 | running_loss = 0.0
1359 | for i, data in enumerate(trainloader, 0):
1360 | # get the inputs; data is a list of [inputs, labels]
1361 | inputs, labels = data
1362 |
1363 | # forward + backward + optimize
1364 | outputs = net(inputs)
1365 | loss = criterion(outputs, labels)
1366 | loss.backward()
1367 | optimizer.step()
1368 |
1369 | # print statistics
1370 | running_loss += loss.item()
1371 | if i % 2000 == 1999: # print every 2000 mini-batches
1372 | st.write(f'[{epoch + 1}, {i + 1:5d}] loss: {running_loss / 2000:.3f}')
1373 | running_loss = 0.0
1374 |
1375 | st.write('Finished Training')
1376 | ```
1377 |
1378 | ### Streamlit with Hugging Face
1379 |
1380 | Streamlit can be integrated with Hugging Face, a popular open-source library for natural language processing (NLP). You can build and deploy NLP models, visualize model performance, and create interactive interfaces for text generation, sentiment analysis, and other NLP tasks.
1381 |
1382 | ```python
1383 | import streamlit as st
1384 | from transformers import pipeline
1385 |
1386 | # Load the sentiment analysis pipeline
1387 | sentiment_pipeline = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
1388 |
1389 | # Get user input
1390 | text = st.text_area("Enter some text for sentiment analysis")
1391 |
1392 | # Perform sentiment analysis
1393 | if text:
1394 | result = sentiment_pipeline(text)
1395 | st.write(f"Sentiment: {result['label']} (Score: {result['score']:.2f})")
1396 | ```
1397 |
1398 | ### Streamlit with LangChain
1399 |
1400 | Streamlit can be integrated with LangChain, a framework for building applications with large language models (LLMs). You can build and deploy LLM-powered applications, create interactive interfaces for querying LLMs, and leverage LangChain's capabilities for tasks like question answering, text generation, and summarization.
1401 |
1402 | ```python
1403 | import streamlit as st
1404 | from langchain import PromptTemplate, OpenAI, LLMChain
1405 |
1406 | # Set up the OpenAI LLM
1407 | llm = OpenAI(model_name="text-davinci-003")
1408 |
1409 | # Define the prompt template
1410 | template = """
1411 | You are a helpful AI assistant. Given the following context, answer the question:
1412 |
1413 | Context: {context}
1414 |
1415 | Question: {question}
1416 | """
1417 | prompt = PromptTemplate(template=template, input_variables=["context", "question"])
1418 |
1419 | # Create the LLM chain
1420 | chain = LLMChain(prompt=prompt, llm=llm)
1421 |
1422 | # Get user input
1423 | context = st.text_area("Enter the context")
1424 | question = st.text_input("Enter your question")
1425 |
1426 | # Generate the answer
1427 | if context and question:
1428 | answer = chain.run(context=context, question=question)
1429 | st.write(f"Answer: {answer}")
1430 | ```
1431 |
1432 | ### Streamlit with OpenAI
1433 |
1434 | Streamlit can be integrated with OpenAI's API, allowing you to build applications that leverage OpenAI's language models, such as GPT-3. You can create interactive interfaces for text generation, question answering, and other natural language processing tasks.
1435 |
1436 | ```python
1437 | import streamlit as st
1438 | import openai
1439 |
1440 | # Set up the OpenAI API key
1441 | openai.api_key = "YOUR_API_KEY"
1442 |
1443 | # Get user input
1444 | prompt = st.text_area("Enter your prompt")
1445 |
1446 | # Generate text using GPT-3
1447 | if prompt:
1448 | response = openai.Completion.create(
1449 | engine="text-davinci-003",
1450 | prompt=prompt,
1451 | max_tokens=1024,
1452 | n=1,
1453 | stop=None,
1454 | temperature=0.7,
1455 | )
1456 |
1457 | generated_text = response.choices.text
1458 | st.write(f"Generated Text: {generated_text}")
1459 | ```
1460 |
1461 | ## Streamlit Contributions
1462 |
1463 | Streamlit is an open-source project, and contributions from the community are welcome and encouraged. Here's how you can contribute to Streamlit:
1464 |
1465 | ### Streamlit GitHub
1466 |
1467 | The Streamlit project is hosted on GitHub, where you can find the source code, report issues, and submit pull requests.
1468 |
1469 | - [Streamlit GitHub Repository](https://github.com/streamlit/streamlit)
1470 |
1471 | ### Streamlit Issues
1472 |
1473 | If you encounter any bugs, issues, or have feature requests, you can report them on the Streamlit GitHub repository's issue tracker.
1474 |
1475 | - [Streamlit Issue Tracker](https://github.com/streamlit/streamlit/issues)
1476 |
1477 | ### Streamlit Pull Requests
1478 |
1479 | If you want to contribute code changes or new features to Streamlit, you can submit a pull request on the GitHub repository.
1480 |
1481 | 1. Fork the Streamlit repository.
1482 | 2. Create a new branch for your changes.
1483 | 3. Make your changes and commit them with descriptive commit messages.
1484 | 4. Push your changes to your forked repository.
1485 | 5. Submit a pull request to the Streamlit repository, describing your changes and their purpose.
1486 |
1487 | ### Streamlit Code of Conduct
1488 |
1489 | Streamlit has a Code of Conduct that outlines the expectations for behavior and interactions within the project community. All contributors are expected to follow this code of conduct.
1490 |
1491 | - [Streamlit Code of Conduct](https://github.com/streamlit/streamlit/blob/develop/.github/CODE_OF_CONDUCT.md)
1492 |
1493 | ## Streamlit FAQ
1494 |
1495 | Here are some frequently asked questions about Streamlit:
1496 |
1497 | 1. **What is Streamlit?**
1498 | Streamlit is an open-source Python library that allows you to create interactive web applications for data science and machine learning projects with minimal effort.
1499 |
1500 | 2. **How does Streamlit work?**
1501 | Streamlit uses a reactive programming model, where the app's user interface is automatically updated in response to user interactions or changes in the underlying data.
1502 |
1503 | 3. **What are the advantages of using Streamlit?**
1504 | Streamlit offers several advantages, including ease of use, interactive widgets, data visualization capabilities, caching and state management, and easy deployment.
1505 |
1506 | 4. **Can Streamlit be used for production applications?**
1507 | Yes, Streamlit can be used for production applications. It provides various deployment options, including Streamlit Sharing, Heroku, AWS, Azure, and GCP.
1508 |
1509 | 5. **How does Streamlit handle state management?**
1510 | Streamlit provides built-in state management capabilities through the `st.session_state` and `st.state` objects, allowing you to store and retrieve data across sessions or within the same session.
1511 |
1512 | 6. **Can Streamlit be integrated with other Python libraries?**
1513 | Yes, Streamlit can be integrated with various Python libraries, such as Pandas, NumPy, Scikit-Learn, TensorFlow, PyTorch, Hugging Face, and LangChain.
1514 |
1515 | 7. **How can I contribute to Streamlit?**
1516 | You can contribute to Streamlit by reporting issues, submitting pull requests, or participating in the Streamlit community forums. Streamlit has a Code of Conduct that outlines the expectations for behavior and interactions within the project community.
1517 |
1518 | 8. **What are some alternatives to Streamlit?**
1519 | Some alternatives to Streamlit include Dash, Voila, Panel, Bokeh, and Plotly Dash. Each library has its own strengths and weaknesses, and the choice depends on your specific requirements and preferences.
1520 |
1521 | 9. **How can I learn more about Streamlit?**
1522 | You can learn more about Streamlit by exploring the official documentation, tutorials, books, courses, and community resources. Streamlit also provides a variety of examples to help you get started and learn by example.
1523 |
1524 | 10. **Is Streamlit free to use?**
1525 | Yes, Streamlit is an open-source project and is free to use for both personal and commercial projects.
1526 |
1527 | ## Streamlit Glossary
1528 |
1529 | Here are some common terms and concepts used in the Streamlit ecosystem:
1530 |
1531 | 1. **Streamlit App**: A Python script that defines the user interface and functionality of a Streamlit application.
1532 |
1533 | 2. **Streamlit Components**: Reusable UI elements that can be used to build Streamlit applications, such as buttons, sliders, and charts.
1534 |
1535 | 3. **Streamlit Caching**: A mechanism provided by Streamlit to improve performance by caching the results of expensive computations or data transformations.
1536 |
1537 | 4. **Streamlit Config**: A set of configuration options that can be used to customize the appearance and behavior of a Streamlit application.
1538 |
1539 | 5. **Streamlit Deployment**: The process of making a Streamlit application available for others to use, either locally or on a remote server.
1540 |
1541 | 6. **Streamlit Layout**: The arrangement and organization of UI elements within a Streamlit application.
1542 |
1543 | 7. **Streamlit Sharing**: A free hosting service provided by Streamlit that allows you to share your Streamlit applications with others.
1544 |
1545 | 8. **Streamlit State Management**: The process of managing and persisting application state across user interactions and sessions.
1546 |
1547 | 9. **Streamlit Theming**: The process of customizing the appearance of a Streamlit application by modifying its CSS styles.
1548 |
1549 | 10. **Streamlit Widgets**: Interactive UI elements provided by Streamlit, such as buttons, sliders, and text inputs, that allow users to interact with the application.
1550 |
1551 | ## Streamlit Cheat Sheet
1552 |
1553 | Here's a concise cheat sheet for some of the most commonly used Streamlit functions and features:
1554 |
1555 | ### Streamlit Write
1556 |
1557 | ```python
1558 | st.write("Hello, World!") # Display text
1559 | st.write(42) # Display a number
1560 | st.write() # Display a list
1561 | ```
1562 |
1563 | ### Streamlit Markdown
1564 |
1565 | ```python
1566 | st.markdown("# This is a Heading") # Render Markdown
1567 | ```
1568 |
1569 | ### Streamlit Widgets
1570 |
1571 | ```python
1572 | st.button("Click me") # Button
1573 | st.checkbox("Check me") # Checkbox
1574 | st.radio("Select an option", ["Option 1", "Option 2"]) # Radio buttons
1575 | st.selectbox("Select an option", ["Option 1", "Option 2"]) # Dropdown
1576 | st.multiselect("Select options", ["Option 1", "Option 2"]) # Multi-select
1577 | st.slider("Select a value", 0, 100, 50) # Slider
1578 | st.text_input("Enter text") # Text input
1579 | st.text_area("Enter text") # Text area
1580 | st.date_input("Select a date") # Date input
1581 | st.time_input("Select a time") # Time input
1582 | st.file_uploader("Upload a file") # File uploader
1583 | st.color_picker("Select a color") # Color picker
1584 | ```
1585 |
1586 | ### Streamlit Data Display
1587 |
1588 | ```python
1589 | st.dataframe(df) # Display a Pandas DataFrame
1590 | st.metric("Temperature", "25°C", "1.2°C") # Display a metric
1591 | st.json(data) # Display JSON data
1592 | st.table(df) # Display a table
1593 | ```
1594 |
1595 | ### Streamlit Charts
1596 |
1597 | ```python
1598 | st.line_chart(data) # Line chart
1599 | st.area_chart(data) # Area chart
1600 | st.bar_chart(data) # Bar chart
1601 | st.pie_chart(data) # Pie chart
1602 | st.altair_chart(chart) # Altair chart
1603 | st.plotly_chart(fig) # Plotly chart
1604 | st.bokeh_chart(plot) # Bokeh chart
1605 | st.deck_gl_chart(viewport, layers) # Deck.gl chart
1606 | st.graphviz_chart(graph) # Graphviz chart
1607 | st.pyplot(fig) # Matplotlib chart
1608 | ```
1609 |
1610 | ### Streamlit Layout
1611 |
1612 | ```python
1613 | col1, col2 = st.columns(2) # Create columns
1614 | with st.expander("Click to expand"): # Expander
1615 | st.write("This content is hidden by default.")
1616 | with st.container(): # Container
1617 | st.write("This content is inside a container.")
1618 | with st.sidebar: # Sidebar
1619 | st.write("This content is in the sidebar.")
1620 | ```
1621 |
1622 | ### Streamlit State Management
1623 |
1624 | ```python
1625 | if "count" not in st.session_state: # Session state
1626 | st.session_state.count = 0
1627 | st.button("Increment", on_click=increment_count)
1628 |
1629 | if "count" not in st.state: # State
1630 | st.state.count = 0
1631 | st.button("Increment", on_click=increment_count)
1632 | ```
1633 |
1634 | ### Streamlit Caching
1635 |
1636 | ```python
1637 | @st.memo # Memoization
1638 | def fibonacci(n):
1639 | # ...
1640 |
1641 | @st.cache_data # Cache data
1642 | def load_data(path):
1643 | # ...
1644 |
1645 | @st.cache_resource # Cache resource
1646 | def load_data():
1647 | # ...
1648 | ```
1649 |
1650 | ### Streamlit Theming
1651 |
1652 | ```python
1653 | st.set_page_config(page_title="My App", page_icon=":guardsman:", layout="wide") # Config
1654 |
1655 | st.markdown("""
1656 |
1662 | """, unsafe_allow_html=True) # Themes
1663 | ```
1664 |
1665 | ### Streamlit Deployment
1666 |
1667 | ```bash
1668 | # Streamlit Sharing
1669 | pip install streamlit-sharing
1670 | streamlit-sharing deploy app.py
1671 |
1672 | # Streamlit Cloud
1673 | pip install streamlit-cloud
1674 | streamlit-cloud deploy app.py
1675 |
1676 | # Heroku
1677 | heroku create my-streamlit-app
1678 | git push heroku master
1679 |
1680 | # AWS Elastic Beanstalk
1681 | eb init
1682 | eb create my-streamlit-app
1683 | eb deploy
1684 |
1685 | # Azure App Service
1686 | az webapp up --name my-streamlit-app
1687 |
1688 | # GCP App Engine
1689 | gcloud app deploy
1690 | ```
1691 |
1692 | ## Streamlit Tips and Tricks
1693 |
1694 | Here are some tips and tricks to help you get the most out of Streamlit:
1695 |
1696 | 1. **Use Caching**: Streamlit provides caching mechanisms to improve performance and reduce computation time. Use `@st.memo`, `@st.cache_data`, and `@st.cache_resource` to cache expensive computations or data transformations.
1697 |
1698 | 2. **Leverage State Management**: Streamlit's state management capabilities (`st.session_state` and `st.state`) allow you to store and retrieve data across sessions or within the same session, enabling you to build stateful applications.
1699 |
1700 | 3. **Modularize Your Code**: Break your Streamlit app into smaller, reusable components or functions to improve code organization and maintainability.
1701 |
1702 | 4. **Use Streamlit Themes**: Customize the appearance of your Streamlit app by using the built-in theming system or creating your own custom CSS styles.
1703 |
1704 | 5. **Optimize Data Loading**: If you're working with large datasets, consider loading and processing the data in a separate thread or process to avoid blocking the main Streamlit thread.
1705 |
1706 | 6. **Leverage Streamlit Components**: Streamlit provides a variety of built-in components and widgets, as well as a community-contributed component library, to enhance the functionality and user experience of your app.
1707 |
1708 | 7. **Utilize Streamlit Layouts**: Use Streamlit's layout features, such as columns, expanders, and containers, to organize and structure your app's content effectively.
1709 |
1710 | 8. **Integrate with Other Libraries**: Streamlit can be integrated with various Python libraries, such as Pandas, NumPy, Scikit-Learn, TensorFlow, PyTorch, Hugging Face, and LangChain, to enhance its capabilities.
1711 |
1712 | 9. **Leverage Streamlit Deployment Options**: Streamlit provides various deployment options, including Streamlit Sharing, Heroku, AWS, Azure, and GCP, allowing you to easily share and deploy your applications.
1713 |
1714 | 10. **Participate in the Streamlit Community**: Join the Streamlit community forums, contribute to the project on GitHub, and stay up-to-date with the latest developments and best practices.
1715 |
1716 | ## Streamlit Roadmap
1717 |
1718 | Streamlit is an actively developed and maintained project, with a roadmap that outlines the future plans and goals for the library. Here are some of the key areas and features that are part of the Streamlit roadmap:
1719 |
1720 | 1. **Performance Improvements**: Streamlit aims to continuously improve the performance and responsiveness of the library, particularly for large-scale applications and datasets.
1721 |
1722 | 2. **Enhanced Data Visualization**: Streamlit plans to expand its data visualization capabilities by integrating with more charting libraries and providing advanced visualization features, such as interactive dashboards and real-time updates.
1723 |
1724 | 3. **Improved Theming and Customization**: Streamlit aims to provide more flexible and powerful theming options, allowing users to customize the appearance and branding of their applications more easily.
1725 |
1726 | 4. **Streamlined Deployment**: Streamlit aims to simplify the deployment process further, making it easier to deploy applications to various platforms and environments.
1727 |
1728 | 5. **Expanded Component Ecosystem**: Streamlit plans to foster a growing ecosystem of community-contributed components, enabling users to extend the functionality of their applications with reusable and modular components.
1729 |
1730 | 6. **Improved Developer Experience**: Streamlit aims to enhance the developer experience by providing better tooling
1731 | 7. , improved debugging capabilities, and more comprehensive documentation and tutorials.
1732 |
1733 | 7. **Collaboration and Sharing**: Streamlit plans to introduce features that facilitate collaboration and sharing of applications, enabling teams to work together more effectively on data science and machine learning projects.
1734 |
1735 | 8. **Improved Accessibility**: Streamlit aims to enhance the accessibility of its applications, ensuring that they are usable by individuals with disabilities and comply with accessibility standards.
1736 |
1737 | 9. **Expanded Language Support**: Streamlit plans to explore support for additional programming languages beyond Python, allowing developers from different backgrounds to leverage the power of Streamlit.
1738 |
1739 | 10. **Integration with Cloud Services**: Streamlit aims to provide seamless integration with various cloud services, enabling users to leverage cloud resources for data storage, computation, and deployment.
1740 |
1741 | 11. **Enhanced Security and Privacy**: Streamlit plans to implement additional security measures and privacy features to ensure the protection of sensitive data and compliance with relevant regulations.
1742 |
1743 | 12. **Improved Scalability**: Streamlit aims to enhance the scalability of its applications, enabling them to handle large-scale data and high-concurrency workloads more efficiently.
1744 |
1745 | 13. **Expanded Use Cases**: Streamlit plans to explore new use cases and domains beyond data science and machine learning, such as business intelligence, financial analytics, and scientific computing.
1746 |
1747 | 14. **Community Engagement**: Streamlit aims to foster a strong and engaged community by encouraging contributions, providing support channels, and organizing events and meetups.
1748 |
1749 | The Streamlit roadmap is subject to change based on user feedback, technological advancements, and the evolving needs of the data science and machine learning communities. Streamlit's development team actively collaborates with the community to prioritize and implement new features and improvements.
1750 |
1751 | ## Streamlit Changelog
1752 |
1753 | Streamlit maintains a detailed changelog that documents the changes, bug fixes, and new features introduced in each release. Here's a summary of some of the notable changes in recent Streamlit releases:
1754 |
1755 | ### Version 1.19.0 (April 2023)
1756 |
1757 | - Added support for Streamlit Components in Streamlit Cloud and Streamlit Sharing.
1758 | - Improved performance and memory usage for large Pandas DataFrames.
1759 | - Introduced `st.metric()` for displaying metrics with optional delta values.
1760 | - Added support for custom CSS in Streamlit Cloud and Streamlit Sharing.
1761 | - Improved error handling and debugging capabilities.
1762 |
1763 | ### Version 1.18.0 (March 2023)
1764 |
1765 | - Introduced `st.cache_resource()` for caching resources across sessions.
1766 | - Added support for Streamlit Components in Streamlit Cloud.
1767 | - Improved performance and memory usage for large datasets.
1768 | - Introduced `st.set_page_config()` for configuring page settings.
1769 | - Added support for custom themes in Streamlit Cloud and Streamlit Sharing.
1770 |
1771 | ### Version 1.17.0 (February 2023)
1772 |
1773 | - Introduced `st.state` for managing state within a single session.
1774 | - Added support for Streamlit Components in Streamlit Sharing.
1775 | - Improved performance and memory usage for large datasets.
1776 | - Introduced `st.deck_gl_chart()` for rendering Deck.gl visualizations.
1777 | - Added support for custom CSS in Streamlit Sharing.
1778 |
1779 | ### Version 1.16.0 (January 2023)
1780 |
1781 | - Introduced `st.cache_data()` for caching data across sessions.
1782 | - Added support for Streamlit Components in local development.
1783 | - Improved performance and memory usage for large datasets.
1784 | - Introduced `st.graphviz_chart()` for rendering Graphviz visualizations.
1785 | - Added support for custom CSS in local development.
1786 |
1787 | ### Version 1.15.0 (December 2022)
1788 |
1789 | - Introduced `st.memo` for memoizing expensive computations.
1790 | - Added support for Streamlit Components in Streamlit Cloud.
1791 | - Improved performance and memory usage for large datasets.
1792 | - Introduced `st.altair_chart()` for rendering Altair visualizations.
1793 | - Added support for custom themes in Streamlit Cloud.
1794 |
1795 | For a complete list of changes and detailed release notes, please refer to the official Streamlit changelog: [Streamlit Changelog](https://github.com/streamlit/streamlit/blob/develop/changelog.md)
1796 |
1797 | ## Streamlit License
1798 |
1799 | Streamlit is released under the Apache License 2.0, which is a permissive open-source license that allows for commercial and non-commercial use, modification, and distribution of the software.
1800 |
1801 | The Apache License 2.0 grants the following permissions:
1802 |
1803 | - **Commercial Use**: You can use Streamlit for commercial purposes, including in proprietary software.
1804 | - **Modification**: You can modify the Streamlit source code and create derivative works.
1805 | - **Distribution**: You can distribute copies of Streamlit, either in its original form or as part of your own software.
1806 | - **Patent Grant**: The license includes a patent grant, which means that contributors to the project grant a patent license for their contributions.
1807 |
1808 | The Apache License 2.0 also includes the following requirements:
1809 |
1810 | - **License and Copyright Notice**: You must include the license and copyright notice in any copies or derivative works of Streamlit.
1811 | - **State Changes**: If you modify the Streamlit source code, you must clearly indicate that changes were made.
1812 | - **Disclaimer of Warranty**: The software is provided "as is," without warranty of any kind, express or implied.
1813 | - **Limitation of Liability**: The contributors of Streamlit are not liable for any damages arising from the use of the software.
1814 |
1815 | By using Streamlit, you agree to comply with the terms and conditions of the Apache License 2.0. For more information, please refer to the official Apache License 2.0 documentation: [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
1816 |
1817 | ## Streamlit Contributing
1818 |
1819 | Streamlit is an open-source project, and contributions from the community are welcome and encouraged. If you're interested in contributing to Streamlit, here are some guidelines to follow:
1820 |
1821 | 1. **Fork the Repository**: Start by forking the Streamlit repository on GitHub. This will create a copy of the repository in your GitHub account.
1822 |
1823 | 2. **Create a Branch**: Create a new branch in your forked repository for your changes. It's a good practice to use a descriptive branch name that reflects the purpose of your changes.
1824 |
1825 | 3. **Make Changes**: Implement your changes or new features in your branch. Ensure that your code follows the Streamlit coding style and conventions.
1826 |
1827 | 4. **Test Your Changes**: Before submitting your changes, make sure to test them thoroughly. Streamlit provides testing utilities and frameworks to help you write and run tests.
1828 |
1829 | 5. **Commit Your Changes**: Commit your changes with clear and descriptive commit messages. This will help other contributors understand the purpose and context of your changes.
1830 |
1831 | 6. **Push to Your Fork**: Push your branch with the committed changes to your forked repository on GitHub.
1832 |
1833 | 7. **Submit a Pull Request**: Navigate to the original Streamlit repository on GitHub and submit a pull request (PR) from your forked branch. Provide a detailed description of your changes, including any relevant information or context.
1834 |
1835 | 8. **Respond to Feedback**: The Streamlit maintainers and community members may provide feedback or request changes to your PR. Be responsive and address any concerns or suggestions raised.
1836 |
1837 | 9. **Merge Your Changes**: Once your PR has been reviewed and approved, it will be merged into the Streamlit codebase by the maintainers.
1838 |
1839 | Before contributing, make sure to review the Streamlit Code of Conduct and follow the guidelines outlined in the project's contributing documentation. Additionally, it's recommended to familiarize yourself with the Streamlit development practices, coding style, and testing frameworks.
1840 |
1841 | By contributing to Streamlit, you'll be part of a vibrant community dedicated to improving and expanding the capabilities of this powerful data science and machine learning library.
1842 |
1843 | ## Streamlit Code of Conduct
1844 |
1845 | The Streamlit project has adopted a Code of Conduct to ensure a respectful, inclusive, and harassment-free environment for all contributors and community members. The Code of Conduct outlines the expected behavior and guidelines for participation in the Streamlit project.
1846 |
1847 | Here are some key points from the Streamlit Code of Conduct:
1848 |
1849 | 1. **Be Respectful**: Treat all individuals with respect, regardless of their background, identity, or experience. Harassment, discrimination, and offensive behavior will not be tolerated.
1850 |
1851 | 2. **Be Inclusive**: Embrace diversity and create an inclusive environment where everyone feels welcome and valued. Respect different perspectives and experiences.
1852 |
1853 | 3. **Be Professional**: Maintain a professional and constructive attitude in all interactions and communications related to the project. Avoid personal attacks, insults, or derogatory language.
1854 |
1855 | 4. **Be Collaborative**: Collaborate openly and constructively with other community members. Provide and accept feedback graciously, and work together towards the project's goals.
1856 |
1857 | 5. **Be Responsible**: Take responsibility for your actions and words. If you witness or experience any violation of the Code of Conduct, report it to the project maintainers.
1858 |
1859 | 6. **Be Ethical**: Uphold ethical standards and act with integrity. Respect intellectual property rights, privacy, and confidentiality.
1860 |
1861 | 7. **Be Mindful**: Be mindful of your words and actions, and consider how they may impact others. Avoid assumptions or biases, and strive to create a welcoming environment for all.
1862 |
1863 | The Streamlit Code of Conduct applies to all project spaces, including the codebase, issue tracker, pull requests, community forums, and any other project-related communication channels. Violations of the Code of Conduct may result in temporary or permanent consequences, as determined by the project maintainers.
1864 |
1865 | By participating in the Streamlit project, you agree to abide by the Code of Conduct and contribute to fostering a positive and inclusive community. For more details, please refer to the official Streamlit Code of Conduct: [Streamlit Code of Conduct](https://github.com/streamlit/streamlit/blob/develop/.github/CODE_OF_CONDUCT.md)
1866 |
1867 | ## Streamlit Security
1868 |
1869 | Streamlit takes security seriously and follows best practices to ensure the safety and integrity of its applications and the data they handle. Here are some key security considerations and measures implemented by Streamlit:
1870 |
1871 | 1. **Input Validation**: Streamlit performs input validation to prevent potential security vulnerabilities, such as cross-site scripting (XSS) and code injection attacks. User input is sanitized and validated before being processed or displayed.
1872 |
1873 | 2. **Secure Deployment**: Streamlit provides secure deployment options, including Streamlit Sharing and Streamlit Cloud, which are hosted on secure infrastructure and follow industry-standard security practices.
1874 |
1875 | 3. **Secure Communication**: When deploying Streamlit applications, communication between the client and server is encrypted using HTTPS to protect data in transit.
1876 |
1877 | 4. **Dependency Management**: Streamlit relies on well-maintained and secure third-party dependencies, which are regularly updated to address potential vulnerabilities.
1878 |
1879 | 5. **Secure Development Practices**: The Streamlit development team follows secure coding practices, including code reviews, static code analysis, and regular security audits.
1880 |
1881 | 6. **Responsible Disclosure**: Streamlit has a responsible disclosure policy in place, encouraging security researchers and users to report any potential vulnerabilities or security issues they discover.
1882 |
1883 | 7. **Regular Updates and Patches**: Streamlit releases regular updates and security patches to address any identified vulnerabilities or security concerns.
1884 |
1885 | 8. **Security Documentation**: Streamlit provides documentation and guidelines on secure deployment, configuration, and usage of its applications, helping users implement security best practices.
1886 |
1887 | 9. **Community Engagement**: Streamlit actively engages with the security community and encourages responsible disclosure of potential vulnerabilities, fostering a collaborative approach to security.
1888 |
1889 | While no software is completely immune to security risks, Streamlit is committed to maintaining a high level of security and continuously improving its security practices. Users are encouraged to follow best practices, keep their Streamlit installations up-to-date, and report any potential security issues through the appropriate channels.
1890 |
1891 | For more information on Streamlit's security practices and responsible disclosure policy, please refer to the official Streamlit documentation and community resources.
1892 |
1893 | ## Streamlit Feedback
1894 |
1895 | Streamlit values feedback from its users and community members. Your feedback helps the Streamlit team understand your needs, identify areas for improvement, and prioritize future development efforts.
1896 |
1897 | Here are some ways you can provide feedback to the Streamlit team:
1898 |
1899 | 1. **GitHub Issues**: If you encounter any bugs, issues, or have feature requests, you can open a new issue on the Streamlit GitHub repository: [Streamlit GitHub Issues](https://github.com/streamlit/streamlit/issues)
1900 |
1901 | 2. **Community Forum**: Streamlit has an active community forum where you can share your feedback, ask questions, and engage with other users and developers: [Streamlit Community Forum](https://discuss.streamlit.io/)
1902 |
1903 | 3. **Twitter**: You can share your feedback, experiences, or suggestions with the Streamlit team and community on Twitter: [Streamlit on Twitter](https://twitter.com/streamlit)
1904 |
1905 | 4. **Email**: If you prefer to provide feedback directly to the Streamlit team, you can send an email to [hello@streamlit.io](mailto:hello@streamlit.io)
1906 |
1907 | 5. **Surveys and Feedback Forms**: Streamlit occasionally conducts surveys or shares feedback forms to gather input from users on specific topics or features.
1908 |
1909 | When providing feedback, it's helpful to include the following information:
1910 |
1911 | - A clear and concise description of your feedback, issue, or feature request.
1912 | - Steps to reproduce the issue (if applicable).
1913 | - Any relevant error messages or logs.
1914 | - Your use case or context for the feedback.
1915 | - Screenshots or examples (if applicable).
1916 | - Your Streamlit version and environment details.
1917 |
1918 | The Streamlit team values all feedback and takes it into consideration during the development and planning process. Your feedback helps shape the future of Streamlit and ensures that it continues to meet the needs of the data science and machine learning communities.
1919 |
1920 | Thank you for your contributions and for being part of the Streamlit community!
1921 |
--------------------------------------------------------------------------------