Skip to main content
Version: 3.2

Get started with Streamlit App

Overviewโ€‹

This article will show you how to publish a Python App with Streamlit in Katonic Platform.

In this tutorial you will:

  • spin a workspace environment with the necessary dependencies to publish a Streamlit App.
  • setup and create sample Streamlit app.
  • publish an App to the Katonic Deploy Launchpad.

Youโ€™ll be working with sample-streamlit app.

It will take approximately 5 minutes to get this example running in Katonic platform.

Setting-up your Workspaceโ€‹

The first step is to create a VS code Workspace capable of running your App.

  1. From the platform , click Workspace.

Untitled

  1. From the Workspaces Overview, click Create Workspace.

Untitled

Fill the following details there:

  • Name : fill your workspace name.

  • Select Environment: select VSCode environment.

  • Image: select VSCode webapps image.

  • Webapp: select Streamlit.

  • Additional Port: 8050.

  • Resources: Desired compute resource for workspace.

Untitled

  1. You will be directed to the Workspace overview window, where you can see your workspace under processing.

Untitled

  1. It will take approximately 2-3 minutes to get this workspace ready.

Untitled

  1. You can connect to your workspace ,when the processing tab changes to running.

    Note: Refresh the page, if your are not seeing processing to running status change after 2-3 minutes.

  2. Click on the connect to use this Workspace for App building.

Required GitHub instructions and setupโ€‹

  1. Once you connect to the your workspace , you will be taken to VSCode Workspace.

Untitled

  1. Before starting anything it is advised that you should connect your GitHub repository to the VSCode workspace.

  2. First create an empty repository in your GitHub account.

  3. Clone that repository to your VSCode Workspace.

  4. Paste below code into terminal.

git clone https://github.com/account-name/repo-name.git
  1. Fill your username and password/token as instructed in vscode workspace.

Untitled

  1. After logging with your git account , you will see your repo folder in workspace.

Untitled

Start the app developmentโ€‹

  1. Write your sample app.py code there or copy below sample code.
from collections import namedtuple
import altair as alt
import math
import pandas as pd
import streamlit as st
import os
routes = os.environ["ROUTE"]
"""
# Welcome to Streamlit!
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).
In the meantime, below is an example of what you can do with just a few lines of code:
"""
with st.echo(code_location='below'):
total_points = st.slider("Number of points in spiral", 1, 5000, 2000)
num_turns = st.slider("Number of turns in spiral", 1, 100, 9)
Point = namedtuple('Point', 'x y')
data = []
points_per_turn = total_points / num_turns
for curr_point_num in range(total_points):
curr_turn, i = divmod(curr_point_num, points_per_turn)
angle = (curr_turn + 1) * 2 * math.pi * i / points_per_turn
radius = curr_point_num / total_points
x = radius * math.cos(angle)
y = radius * math.sin(angle)
data.append(Point(x, y))
st.altair_chart(alt.Chart(pd.DataFrame(data), height=500, width=500)
.mark_circle(color='#0068c9', opacity=0.5)
.encode(x='x:Q', y='y:Q'))

Note: Always define the routes as given in sample code, routes = os.environ["ROUTE"]

Note: Always keep the port = 8050

Test your appโ€‹

  1. Create the requirements.txt file with all required dependency.

  2. Here is the requirements.txt code used in above app.

altair
pandas
streamlit

Note: type following command in the terminal.

pip install -r requirements.txt
streamlit run app.py --server.port=8050 --server.address=0.0.0.0

Untitled

Note: keep the path relative to your folder structure.

Note: keep your app name as app.py and requirement file as requirements.txt

  1. Go back to the Workspaces.

  2. Click on the Live app to see your app.

Untitled

  1. Your app will open on the new tab.

Untitled

  1. Finally commit and push your code to the GitHub.
git config user.email 'youremail@domain.com'
git config user.name 'youraccount-name'
git add .
git commit -m ' your msg'
git push

Note: Follow the necessary GitHub instructions as pop up by VSCode to complete code push.

Deploy your Appโ€‹

  1. To deploy your app, go to the Deploy tab and click on the +create Deployment button and select Apps.

Untitled

  1. You will see below form window.

Untitled

  1. Fill the details as follow:
  • App Name: your app name.

  • Select Environment: your app environment.

  • Github Token: your github token.

  • Username: your github account.

  • Account Type: select your account personal or organisation.

  • Repository Branch: choose app repo from drop down.

  • Main file path: appfile name with extention.

  • Python Version: choose desired python version for app.

  • Resources: choose desired compute resources.

Untitled

  1. Click on the Deploy button , it will take you to the Deploy window again.

Untitled

  1. Here you can see your App deployment status processing.

  2. After few minutes status will change to running.

Untitled

  1. check the logs.

Untitled

  1. you can view the current status and check if the deployed app is ready to go.

Untitled

  1. Click on App Url to see the deployed app.

Untitled

You can share the App Url to showcase your work.

Untitled