Tutorial Python | Instalasi dan Membuat Aplikasi Sederhana Menggunakan Streamlit

3 min read 1 month ago
Published on Oct 31, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

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.

  1. Download Python:

    • Go to the official Python website.
    • Choose the latest version of Python and download the installer for your operating system.
  2. 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.

  1. Open Command Prompt or Terminal:

    • On Windows, search for "cmd" in the start menu.
    • On macOS or Linux, open the Terminal application.
  2. 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.

Step 3: Create a Simple Streamlit Application

Now that Streamlit is installed, you can create your first application.

  1. 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
      
  2. 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.
  3. 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.

Step 4: Run Your Streamlit Application

To see your application in action, you need to run the Streamlit server.

  1. Go Back to Command Prompt or Terminal:

    • Ensure you are in the directory where app.py is located.
  2. 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.

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!