Widgets
ウィジェット(Widgets)とは、グラフィカルユーザインタフェース(GUI)のインタフェース部品の総称。(テキストボックス チェックボックスなど)
スライダー入力
st.slider() スライダー表示し、入力値を取得し入力値の自乗値を表示する。
import streamlit as st x = st.slider('x') # 👈 this is a widget st.write(x, 'squared is', x * x)テキスト入力
import streamlit as st title = st.text_input('Movie title', 'Life of Brian') st.write('The current movie title is', title) st.text_input("Your name", key="name") # You can access the value at any point with: st.session_state.name起動
アップグレード要求表示のため実施。
PS C:\Users\omo\test> pip install streamlit --upgrade
Requirement already satisfied: streamlit in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (1.8.1)
Collecting streamlit
Downloading streamlit-1.9.0-py2.py3-none-any.whl (10.1 MB)
---------------------------------------- 10.1/10.1 MB 8.7 MB/s eta 0:00:00
Requirement already satisfied: pillow>=6.2.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (9.1.0)
Requirement already satisfied: attrs in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (21.4.0)
Requirement already satisfied: cachetools>=4.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (5.0.0)
Requirement already satisfied: python-dateutil in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (2.8.2)
Requirement already satisfied: tzlocal in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (4.2)
Requirement already satisfied: altair>=3.2.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (4.2.0)
Requirement already satisfied: pyarrow in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (7.0.0)
Requirement already satisfied: numpy in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (1.22.3)
Requirement already satisfied: pydeck>=0.1.dev5 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (0.7.1)
Requirement already satisfied: tornado>=5.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (6.1)
Requirement already satisfied: packaging in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (21.3)
Requirement already satisfied: protobuf!=3.11,>=3.6.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (3.20.1)
Requirement already satisfied: validators in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (0.18.2)
Requirement already satisfied: gitpython!=3.1.19 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (3.1.27)
Requirement already satisfied: toml in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (0.10.2)
Requirement already satisfied: importlib-metadata>=1.4 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (4.11.3)
Requirement already satisfied: click<8.1,>=7.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (8.0.4)
Requirement already satisfied: semver in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (2.13.0)
Requirement already satisfied: blinker in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (1.4)
Requirement already satisfied: pympler>=0.9 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (1.0.1)
Requirement already satisfied: pandas>=0.21.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (1.4.2)
Requirement already satisfied: watchdog in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (2.1.7)
Requirement already satisfied: requests in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from streamlit) (2.27.1)
Requirement already satisfied: jsonschema>=3.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from altair>=3.2.0->streamlit) (4.4.0)
Requirement already satisfied: entrypoints in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from altair>=3.2.0->streamlit) (0.4)
Requirement already satisfied: toolz in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from altair>=3.2.0->streamlit) (0.11.2)
Requirement already satisfied: jinja2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from altair>=3.2.0->streamlit) (3.1.2)
Requirement already satisfied: colorama in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from click<8.1,>=7.0->streamlit) (0.4.4)
Requirement already satisfied: gitdb<5,>=4.0.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from gitpython!=3.1.19->streamlit) (4.0.9)
Requirement already satisfied: zipp>=0.5 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from importlib-metadata>=1.4->streamlit) (3.8.0)
Requirement already satisfied: pytz>=2020.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from pandas>=0.21.0->streamlit) (2022.1)
Requirement already satisfied: ipywidgets>=7.0.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from pydeck>=0.1.dev5->streamlit) (7.7.0)
Requirement already satisfied: traitlets>=4.3.2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from pydeck>=0.1.dev5->streamlit) (5.1.1)
Requirement already satisfied: ipykernel>=5.1.2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from pydeck>=0.1.dev5->streamlit) (6.13.0)
Requirement already satisfied: six>=1.5 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from python-dateutil->streamlit) (1.16.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from packaging->streamlit) (3.0.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from requests->streamlit) (1.26.9)
Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from requests->streamlit) (2.0.12)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from requests->streamlit) (2021.10.8)
Requirement already satisfied: idna<4,>=2.5 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from requests->streamlit) (3.3)
Requirement already satisfied: tzdata in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from tzlocal->streamlit) (2022.1)
Requirement already satisfied: pytz-deprecation-shim in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from tzlocal->streamlit) (0.1.0.post0)
Requirement already satisfied: decorator>=3.4.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from validators->streamlit) (5.1.1)
Requirement already satisfied: smmap<6,>=3.0.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from gitdb<5,>=4.0.1->gitpython!=3.1.19->streamlit) (5.0.0)
Requirement already satisfied: matplotlib-inline>=0.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.1.3)
Requirement already satisfied: nest-asyncio in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (1.5.5)
Requirement already satisfied: ipython>=7.23.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (8.3.0)
Requirement already satisfied: jupyter-client>=6.1.12 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (7.3.0)
Requirement already satisfied: psutil in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (5.9.0)
Requirement already satisfied: debugpy>=1.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (1.6.0)
Requirement already satisfied: jupyterlab-widgets>=1.0.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (1.1.0)
Requirement already satisfied: ipython-genutils~=0.2.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.2.0)
Requirement already satisfied: widgetsnbextension~=3.6.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (3.6.0)
Requirement already satisfied: nbformat>=4.2.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (5.3.0)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from jinja2->altair>=3.2.0->streamlit) (2.1.1)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from jsonschema>=3.0->altair>=3.2.0->streamlit) (0.18.1)
Requirement already satisfied: backcall in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.2.0)
Requirement already satisfied: setuptools>=18.5 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (58.1.0)
Requirement already satisfied: stack-data in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.2.0)
Requirement already satisfied: pickleshare in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.7.5)
Requirement already satisfied: pygments>=2.4.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (2.12.0)
Requirement already satisfied: jedi>=0.16 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.18.1)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (3.0.29)
Requirement already satisfied: jupyter-core>=4.9.2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from jupyter-client>=6.1.12->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (4.10.0)
Requirement already satisfied: pyzmq>=22.3 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from jupyter-client>=6.1.12->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (22.3.0)
Requirement already satisfied: fastjsonschema in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbformat>=4.2.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (2.15.3)
Requirement already satisfied: notebook>=4.4.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (6.4.11)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from jedi>=0.16->ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.8.3)
Requirement already satisfied: pywin32>=1.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from jupyter-core>=4.9.2->jupyter-client>=6.1.12->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (303)
Requirement already satisfied: argon2-cffi in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (21.3.0)
Requirement already satisfied: nbconvert>=5 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (6.5.0)
Requirement already satisfied: Send2Trash>=1.8.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (1.8.0)
Requirement already satisfied: prometheus-client in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.14.1)
Requirement already satisfied: terminado>=0.8.3 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.13.3)
Requirement already satisfied: wcwidth in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.2.5)
Requirement already satisfied: pure-eval in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from stack-data->ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.2.2)
Requirement already satisfied: executing in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from stack-data->ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (0.8.3)
Requirement already satisfied: asttokens in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from stack-data->ipython>=7.23.1->ipykernel>=5.1.2->pydeck>=0.1.dev5->streamlit) (2.0.5)
Requirement already satisfied: tinycss2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (1.1.1)
Requirement already satisfied: beautifulsoup4 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (4.11.1)
Requirement already satisfied: defusedxml in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.7.1)
Requirement already satisfied: nbclient>=0.5.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.6.0)
Requirement already satisfied: pandocfilters>=1.4.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (1.5.0)
Requirement already satisfied: bleach in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (5.0.0)
Requirement already satisfied: mistune<2,>=0.8.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.8.4)
Requirement already satisfied: jupyterlab-pygments in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.2.2)
Requirement already satisfied: pywinpty>=1.1.0 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from terminado>=0.8.3->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (2.0.5)
Requirement already satisfied: argon2-cffi-bindings in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (21.2.0)
Requirement already satisfied: cffi>=1.0.1 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from argon2-cffi-bindings->argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (1.15.0)
Requirement already satisfied: soupsieve>1.2 in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from beautifulsoup4->nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (2.3.2.post1)
Requirement already satisfied: webencodings in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from bleach->nbconvert>=5->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (0.5.1)
Requirement already satisfied: pycparser in c:\users\omo\appdata\local\programs\python\python310\lib\site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->notebook>=4.4.1->widgetsnbextension~=3.6.0->ipywidgets>=7.0.0->pydeck>=0.1.dev5->streamlit) (2.21)
Installing collected packages: streamlit
Attempting uninstall: streamlit
Found existing installation: streamlit 1.8.1
Uninstalling streamlit-1.8.1:
Successfully uninstalled streamlit-1.8.1
Successfully installed streamlit-1.9.0
PS C:\Users\omo\test>オプションに選択ボックスを使用
import streamlit as st import pandas as pd df = pd.DataFrame({ 'first column': [1, 2, 3, 4], 'second column': [10, 20, 30, 40] }) option = st.selectbox( 'Which number do you like best?', df['first column']) 'You selected: ', option