Presented as a ligtning talk on 4th June, 2021 at the Wadhwani Institute of Artificial Intelligence.
Presentation link
- Install the requirements
pip install -r requirements.txt
- Run any of the following files with the command
streamlit run <filename.py>
app1.py
app2.py
cropper.py
page.py
page_state.py
- You can run the streamlit demo with
streamlit hello
Custom components are for additional widget functionality that is not covered by Streamlit widgets out-of-the-box
- Using custom components
- Go to streamlit components gallery
- Check if someone has built the component you want
- An example can be seen by running
streamlit run cropper.py
- Building custom components
Explanation coming soon
- (Without state)
streamlit run page.py
- (WITH state)
streamlit run page_state.py
- Copy the state.py file to your directory.
- Use
from state import get
in the file that you maintain state in. - Use
ret_state = get(a=0, b=0)
where the get function will take in all variables (a
,b
) that you want to maintain state for, with their initial values (a=0
,b=0
). - Values can be read from the state using
state.a
- New values can be updated to the state by using
state.a = 5
- In summary, replace
a
in the code without state bystate.a
and move the initialisation to theget
function. - Please compare
page.py
(without state) andpage_state.py
(with state) for an example use of state.
-
(RECOMMENDED) Streamlit Sharing
- Log on to streamlit sharing page through your Github account
- Pick the repo, branch and file that you want to deploy
- Submit and it will give a shareable URL of your app!
- Any commits made to the branch chosen in step 2 will trigger a re-deploy of the new version of the app!
-
Using AWS EC2 like services
- ssh into the instance
- clone and run your app through
streamlit run <filename.py>
- The
Network URL
that is displayed is the shareable URL of your app! - The network settings of your security-group have to be changed to allow traffic to the streamlit port and all IP addresses.
- The public IP of an AWS instances changes everytime we restart it. To have the same IP, it can be assigned a static IP through Elastic IPs (free).
-
Using Github Gists
- This method is only for distributing your app. It will not deploy it anywhere. Users can run the app easily on their own instances!
- Distribute the URL of your Github Gist's raw version. You can find the raw version by going to the normal gist url and clicking raw on the file that you want to share.
- (Incorrect) Github gist url
- (Correct) Github gist raw url
- Users can run the app on their machine through
streamlit run <replace_gist_raw_url>
- Custom components gallery
Before building a component, check this link if someone has already built it - Building custom components
- Gist that contains the code for maintaining state
- Shareable gist for app2.py
- Talk slides