Streamlit is an open-source app framework in python language. It helps us create beautiful web apps for data science and machine learning in a little time. It is compatible with major python libraries such as scikit-learn, keras, PyTorch, latex, numpy, pandas, matplotlib, etc. Syntax for installing this library is shown below.
Install StreamLit :
Before you get started, there’re a few things you’re going to need :
1. Download an IDE or text editor
2. Install Python in your system (preferably Python 3.7 – Python 3.10)
3. Install PIP in your system.
Set up your virtual environment
First of all we need to setup a virtual environment to run few commands. This will ensure that the dependencies installed/updated for Streamlit will not impact any other Python projects on the system. Tools that you can use for environment management: pipenv, poetry, venv, virtualenv, conda.
Anaconda Navigator is Streamlit’s officially-supported environment manager on Windows, hence we need to download that.
Install Anaconda
If you don’t have Anaconda install yet, follow this article to install it – how-to-install-anaconda-on-windows.
Create a new environment with Streamlit
Now we will be setting up the environment.
- Anaconda provides steps for setting up Anaconda and managing the environment through the Anaconda Navigator. Follow them and setup Anaconda.
- Next, select the “▶” icon appearing next to your new environment. Then we need to select “Open terminal” from the menu that appears.
- In the command-prompt type
pip install streamlit
- Now, test that the installation worked using the command-
streamlit hello
Creating a Simple application (Hello World) –
The 'hello, world!' script in Streamlit: streamlit hello # to run your python script streamlit run myFirstStreamlitApp.py
You can stop running your app any time using Ctrl + C.
Check the Streamlit Version using Terminal
Open the terminal and write the command in your terminal:
streamlit --version
This command should tell you what version the installed streamlit package is.
Check the Streamlit Version using the pip
Using the pip command gives all the detail of current versions of python modules which you installed in your system.
To check Streamlit version,open your terminal and write the pip command in your terminal. If Streamlit is not currently installed in your system, it will not appear in the list of modules.
pip freeze
Update Streamlit Version
If you want to update your Streamlit version you can use any one of these commands to update your Streamlit.
python -m pip install --upgrade Streamlit
python -m pip install -U Streamlit
This will update your Streamlit to the latest version.
Advantages of Streamlit :
1. It embraces python-scripting.
2. Less code is needed to create amazing web-apps.
3. No callbacks are needed since widgets are treated as variables.
4. Data caching simplifies and speeds up computation pipelines.
Disadvantages of Streamlit :
1. Streamlit’s Data caching cannot keep track of changes to the data happening outside the function body.
Some of its basic functions are described here.
1. Adding a Title
Python3
# myFirstStreamlitApp.py # import the library import streamlit as stl # add title to your app stl.title( "Geeks for Geeks" ) |
Output:
2. Adding some text
Python3
# myFirstStreamlitApp.py # import the library import streamlit as stl # add title to your app stl.title( "Geeks for Geeks" ) # adding text to your app stl.write( "A Computer Science portal for Geeks" ) |
Output: