LoginSignup
0
1

【Streamlit】Webに公開する

Last updated at Posted at 2023-05-17

※私は下記のコードを使い回します。

main.py
import streamlit as st
import time

st.title('Streamlit 基本操作')

'スタート'

latest_iteration = st.empty()
bar = st.progress(30)

'スタート'

latest_iteration = st.empty()
bar = st.progress(0)

for i in range(100):
    latest_iteration.text(f'Interation {i+1}')
    bar.progress(i + 1)
    time.sleep(0.1)

expander1 = st.expander('問い合わせ')
expander1.write('問い合わせ内容を書く')
expander2 = st.expander('問い合わせ')
expander2.write('問い合わせ内容を書く')
expander3 = st.expander('問い合わせ')
expander3.write('問い合わせ内容を書く')

必要なこと

・Streamlit Shearing
・git

Streamlit Shearing

Streamlitの公式ページからユーザー登録・ログインを行います。

ログインすると以下のページが表示されます。

image.png

git

GitHubでリポジトリを作成しておきまう。
詳細説明は省きます。

requirements.txt

requirements.txtを作成します。
このファイルには、開発しているアプリケーションで使う外部ライブラリを記載します。

requirements.txt→外部のライブラリ
main.py→pythonの標準ライブラリ

で分けて記述していきます。

streamlitのみrequirements.txtに移します。

requirements.txt
streamlit

コマンド

pip freeze

様々なライブラリのバージョンの一覧が表示されます。

image.png

streamlitを探し、requirements.txtに貼り付けます。
※バージョン指定しない場合は、自動的に最新のものになります。

ここでGitにプッシュしておきます。

image.png

画面右のNew appをクリック。
必要事項を記入していきます。

上から
・GitHubで使用するリポジトリ名
・GitHubの現在のブランチ名
・実行したいファイル名を指定

image.png

最後にDeployをクリックし、書いたコードが無事に実行されれば公開成功です。

image.png

画面右したのmanage appをクリックすると、ログが表示されるサイドバーが出てきます。

image.png

試しにURLをコピーして他のブラウザに張り付けても、正常に動いています。

image.png

アプリケーションを複数追加したいとき

Your appsをクリックします。

image.png

作成済みアプリケーションの一覧が表示されます。
New appをクリックすれば、アプリケーションが追加されます。

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1