Tutorial Python | Instalasi dan Membuat Aplikasi Sederhana Menggunakan Streamlit
Table of Contents
Introduction
In this tutorial, you will learn how to install Streamlit and create a simple application using this powerful framework. Streamlit is a popular tool for building web applications quickly, especially for data science projects. This guide provides a step-by-step approach to get you started with your first Streamlit app.
Step 1: Install Python
Before you can use Streamlit, you need to ensure that Python is installed on your machine.
-
Download Python:
- Go to the official Python website.
- Choose the latest version of Python and download the installer for your operating system.
-
Install Python:
- Run the installer.
- Make sure to check the box that says "Add Python to PATH" during installation.
- Follow the prompts to complete the installation.
Step 2: Install Streamlit
Once Python is installed, you can install Streamlit using pip, Python’s package installer.
-
Open Command Prompt or Terminal:
- On Windows, search for "cmd" in the start menu.
- On macOS or Linux, open the Terminal application.
-
Run the Installation Command:
- Type the following command and press Enter:
pip install streamlit
- Wait for the installation to complete. You should see a message indicating the successful installation.
- Type the following command and press Enter:
Step 3: Create a Simple Streamlit Application
Now that Streamlit is installed, you can create your first application.
-
Create a New Directory:
- Navigate to the location where you want to create your project using the command line.
- Create a new directory by running:
mkdir my_first_streamlit_app cd my_first_streamlit_app
-
Create the Python Script:
- Open a text editor or IDE of your choice (e.g., VSCode, PyCharm).
- Create a new Python file named
app.py
.
-
Write Your First Streamlit Code:
- Add the following code to
app.py
:import streamlit as st st.title('Hello, Streamlit!') st.write('This is my first Streamlit app.')
- Save the file.
- Add the following code to
Step 4: Run Your Streamlit Application
To see your application in action, you need to run the Streamlit server.
-
Go Back to Command Prompt or Terminal:
- Ensure you are in the directory where
app.py
is located.
- Ensure you are in the directory where
-
Run the Application:
- Execute the following command:
streamlit run app.py
- This will open your default web browser and navigate to the local URL where your app is running, typically
http://localhost:8501
.
- Execute the following command:
Conclusion
Congratulations! You have successfully installed Streamlit and created your first simple web application. You can now explore more features of Streamlit, such as adding interactivity, charts, and data visualization. Consider diving deeper into the Streamlit documentation to enhance your applications and leverage its full potential. Happy coding!