Code Monkey home page Code Monkey logo

streamlit-routing's Introduction

streamlit-routing

A sample environment for launching multiple streamlit and proxying from routing to the desired streamlit app. Streamlit usually accesses localhost:8901 , localhost:8902, etc., but this method is used to access them as localhost:80/sample1 and localhost:80/sample2.

複数のstreamlitを起動し、routingから目的のstreamlit appへプロキシする環境のサンプル。 streamlit は通常 localhost:8901 , localhost:8902 などにアクセスするが、これを localhost:80/sample1localhost:80/sample2 のようにアクセスするための方法。

Requirements

Getting Started

You can check in the following ways.

以下の方法で確認できます。

$ make create-image
$ make creatio-container

...open other terminal window

$ open localhost:8888/sample

How to use

streamlit

First, we create the streamlit app. We have a separate working directory for each application.

まず、streamlit appを作ります。 各アプリケーションごとに作業ディレクトリを分けるようにしています。

src/
├─ sample1/
│  ├─ app.py
├─ sample2/
│  ├─ app.py
├─ <<< add new your working dir >>>

The directory name is the name you want to match in the routing.

ディレクトリ名はルーティングでマッチさせたい名前にしています。

nginx

Add to nginx.conf in the same way as /sample.

/sample と同様にnginx.confに追記していきます。

http {
	server {
		location /sample {
			proxy_pass http://0.0.0.0:8901/sample;
		}

		location /sample/stream {
			proxy_pass http://0.0.0.0:8901/sample/stream;
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto $scheme;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";
			proxy_read_timeout 2h;
		}

    <<< add your new routing >>>
	}
}

docker/entrypoint.sh

Finally, add the startup command to entrypoint.sh. Add the path and port number you want to use for startup. Make sure it doesn't overlap with any other streamlit app.

最後に、entrypoint.shに起動コマンドを追記します。 起動時に使いたいパスとポート番号を書きます。 他のstreamlit app と重複しないようにします。

#!/bin/bash

nohup streamlit run --server.port=8901 --server.baseUrlPath=sample1 src/sample1/app.py &
nohup streamlit run --server.port=8902 --server.baseUrlPath=sample2 src/sample2/app.py &
<<< add your new streamlit app launching command >>>
service nginx start

How it works

nginx

単純にnginxのリバースプロキシを使っています。 docker/nginx/nginx.confhttpブロックを確認するとわかります。

Simply using nginx's reverse proxy. It can be seen by checking the http block in docker/nginx/nginx.conf.

streamlit

各streamlit appの起動ごとにbasePathConfigport を指定しています。 ディレクトリに分けているので、重複に気付きやすいです。

For each streamlit app launch, we specify the basePathConfig and port. We have separated them into directories, so it's easy to notice the duplication.

Credits

streamlit-routing's People

Contributors

funwarioisii avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.