plotly/dash
と比較されることが多いjavascript
不要、スクリプトライクな記述matplotlib
, plotly
, altair
, ...pip install streamlit
%%writefile app.py
import streamlit as st
st.write("# Hello, Streamlit!")
Overwriting app.py
!streamlit run app.py
You can now view your Streamlit app in your browser. Network URL: http://172.17.0.2:8501 External URL: http://49.251.189.62:8501 ^C Stopping...
streamlit
コマンドを実行%%writefile app.py
import streamlit as st
st.write("# Hello, Streamlit!")
st.write("# Where is Rerun button?")
Overwriting app.py
%%writefile app.py
import streamlit as st
st.write("# Hello, Streamlit!")
raise ValueError
Overwriting app.py
st.write
¶%%writefile app.py
import numpy as np
import pandas as pd
import streamlit as st
st.write([1, 2, 3])
st.write({"hello": "world!"})
st.write(np.arange(10).reshape(1,10))
st.write(pd.DataFrame(np.random.randn(10, 4), columns=["1", "2", "3", "4"]))
Overwriting app.py
master
heroku
espnet2
Steramlit
のバージョンは0.66.0streamlit run https://github.com/user/repos.git/master/app.py
scipy.signal
を使用Streamlit
によるアプリ構築をライブコーディング的に実施selectbox
で表示st.sidebar.xxx
st.xxx
と本体に配置できるウィジェットは何でも配置可能%%writefile app.py
import streamlit as st
windows = ["boxcar", "triang", "blackman", "hamming", "hann", "bartlett", "flattop",
"parzen", "bohman", "blackmanharris", "nuttall", "barthann"]
Overwriting app.py
%%writefile -a app.py
でapp.py
に追記%%writefile -a app.py
win_name = st.sidebar.selectbox("window", windows, 4)
st.write(win_name)
Appending to app.py
st.selectbox
で2の累乗の値を取得%%writefile -a app.py
two_powers = [2**i for i in range(16)]
Nx = st.sidebar.selectbox("Window Length", two_powers, 8)
nfft = st.sidebar.selectbox("FFT Length", two_powers, 10)
st.write(win_name, Nx, nfft)
Appending to app.py
scipy.signal.get_window
scipy.fft.fft
で周波数分析%%writefile -a app.py
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal as sg
import scipy.fft as fft
Appending to app.py
%%writefile -a app.py
eps = 1.e-12
win = sg.get_window(win_name, Nx)
W = 20.0 * np.log10(np.abs(fft.fft(win, nfft)) + eps)
W = fft.fftshift(W)
Appending to app.py
matplotlib
を用いて描画%%writefile -a app.py
fig, axes = plt.subplots(2, 1)
axes[0].plot(win)
axes[1].plot(W)
st.pyplot(fig)
Appending to app.py
st.pyplot
¶matplotlib
のfigureを描画st.pyplot(fig)
streamlit
の描画ライブラリ¶st.line_chart
, st.area_chart
, st.bar_chart
st.altair_chart
のsyntax sugarvega
, plotly
, bokeh
なども使用可能%%writefile -a app.py
st.line_chart(win)
st.line_chart(W)
Appending to app.py
st.line_chart
の見た目!cat app.py | pygmentize
import streamlit as st windows = ["boxcar", "triang", "blackman", "hamming", "hann", "bartlett", "flattop", "parzen", "bohman", "blackmanharris", "nuttall", "barthann"] win_name = st.sidebar.selectbox("window", windows, 4) st.write(win_name) two_powers = [2**i for i in range(16)] Nx = st.sidebar.selectbox("Window Length", two_powers, 8) nfft = st.sidebar.selectbox("FFT Length", two_powers, 10) st.write(win_name, Nx, nfft) import matplotlib.pyplot as plt import numpy as np import scipy.signal as sg import scipy.fft as fft eps = 1.e-12 win = sg.get_window(win_name, Nx) W = 20.0 * np.log10(np.abs(fft.fft(win, nfft)) + eps) W = fft.fftshift(W) fig, axes = plt.subplots(2, 1) axes[0].plot(win) axes[1].plot(W) st.pyplot(fig) st.line_chart(win) st.line_chart(W)
st.multiselect(ラベル名, 選択肢のリスト, デフォルト項目の要素のリスト)