1
3

Streamlitを使ってみる:その2

Posted at

その1の続きです。

1. シミュレーション結果のプロット

サイドバーにスライダーを配置して、プロットの変化をシミュレーションします。st.sidebar.sliderで簡単に実装できます。

test_st5.py
import streamlit as st
import numpy as np
import pandas as pd

amp = st.sidebar.slider("振幅",0,20)
ocs = st.sidebar.slider("振動時間",1,20)

x = np.linspace(0,ocs,1000)
y = np.sin(x)*amp

data = pd.DataFrame({
   "x":x,
   "y":y
})

st.line_chart(data,x="x",y="y")

streamlit_test5-1.png

streamlit_test5-2.png

streamlit_test5-3.png

x軸,y軸の範囲は、スワイプ操作で簡単に変更できます。

streamlit_test5-4.png

2. 複数のページの作成と遷移

参考URL

ターミナルで、メインページの.pyファイルと同じ階層にpagesフォルダを作成します。

 % mkdir pages
pages/page1.py
import streamlit as st

st.write("test page a")
pages/page2.py
import streamlit as st

st.write("test page a")

サイドバーにメニューができました。

streamlit_test6-1.png

クリックすると別のページに飛びます。

streamlit_test6-2.png

streamlit_test6-3.png

これは便利機能ですね。


その3に続く(多分)

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