Streamlit is an open-source tool that is used for Python dashboards and web applications. When you are done with the coding part, it is now time to run your Streamlit App. In this short article, we will discuss how to run the Streamlit app in various editors including VS Code, Jupyter Notebook, and Google Colab. In general, the streamlit run [appName.py] is used to run the web app.
How to Run Streamlit App?
Well, the process is very simple. All you need is to open the terminal and type streamlit run [name.py] and it will open the application in the default web browser on your PC.
Let us say that we have a Streamlit application in a file name app.py. Then, we can follow the given steps to run the streamlit app in vs code
- Open the app.py file in VS Code
- Open a new terminal in VS Code
- Type “streamlit run app.py’, and hit enter
- The app will run on the local host and a new web browser will open
- Congratulations on running the app successfully.
How to Run Streamlit App in Jupyter Notebook or Colab?
Well, It is not possible to run the Streamlit app inside a Jupyter Notebook. There can be several reasons for it. One of the common reasons is that the Streamlit app starts a server on the main thread which means if we run it inside Jupyter Notebook then the kernel of Jupyter Notebook will be closed and we will not be able to use it anymore.
Example of Running Streamlit App in VS Code
Now, you are familiar with the running of the app in a web browser. Let us go through a simple example and see how to run the Streamlit app in VS Code.
First, let us import the required modules.
import streamlit as st
Now, we will write the script for our Streamlit app. Here for the sake of understanding, we will just type the title of the web app and then we will run it.
st.title("Example Web Application")
Now, open the terminal and type the given commands. In our case, the name of our Python file is app.py so we will use it.
streamlit run app.py
Now, a new tab will open in the web browser showing you the web application.
Congratulations on successfully running the web application.
Streamlit is a new and cool Python module that made the web application so simple. Now, we can create interactive dashboards and web apps using a few lines of code. In this short article, we discussed how we can run the Streamlit app on VS code studio using the terminal.
Articles Related To Steamlit
- How to Display an Image in Streamlit From a Folder?
- Create Streamlit Button and Style Streamlit Buttons in Python