0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Streamlitの基本的なUIコンポーネント

Posted at

1. ボタン

import streamlit as st

# ボタンを押した際の挙動を設定する。
if st.button("ボタン"):
    st.write("ボタンが押されました!")
else:
    st.write("ボタンはまだ押されていません。")

2. チェックボックス

# チェックボックスの状態を確認する。
check = st.checkbox("チェックボックス")
if check:
    st.write("チェックされました。")
else:
    st.write("まだチェックされていません。")

3. トグル

# トグルスイッチの状態を取得する。
toggle = st.toggle("トグル")
if toggle:
    st.write("現在はONです。")
else:
    st.write("現在はOFFです。")

4. ラジオボタン

# ラジオボタンを使って色を選択する。
color = st.radio(
    "色を選んでください",
    ("", "", "")
)
st.write(f"選んだ色: {color}")

5. ドロップダウンリスト

# 1つの値を選択できるドロップダウンリスト。
fruits = st.selectbox(
    "フルーツを選んでください",
    ("りんご", "オレンジ", "バナナ")
)

st.write(f"選んだフルーツ: {fruits}")

6. 複数選択可能なリスト

# 複数の値を選択できるドロップダウンリスト。
colors = st.multiselect(
    "色を選んでください",
    ["", "", "", "", "", ""]
)
# 選択した値はリストで取得される。
st.write(f"選んだ色: {colors}")

7. スライダー

# スライダーで数値を選択する。
# 0歳から100歳まで5歳刻みで選べる設定(初期値は20歳)。
age = st.slider('年齢を選択してください', 0, 100, 20, 5)
st.write(f"選んだ年齢: {age}")

8. 日付入力

# 日付を選択する。
date = st.date_input("日付")
st.write(f"選択した日付: {date}")

9. 時間入力

# 時刻を入力する。
time = st.time_input("時刻")
st.write(f"設定した時刻: {time}")

10. テキスト入力(1行)

# 1行のテキストを入力する。
text_single = st.text_input("テキストを入力してください。")
st.write(f"入力内容: {text_single}")

11. テキスト入力(複数行)

# 複数行のテキストを入力する。
text_multi= st.text_area("テキストを入力してください。")
# 出力はマークダウン形式で表示される。
st.write(f"入力内容: {text_multi}")
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?