File size: 3,267 Bytes
0e312f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b945c6c
0e312f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b945c6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96edb53
 
b945c6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import streamlit as st
import uuid

# クリックするたび数字が増える
st.subheader("1.クリックするたび数字が増える")
if 'count' not in st.session_state:
  st.session_state["count"] = 0
  
if st.button("カウント", key=0):
  st.session_state["count"] += 1
  
st.write("カウント", st.session_state["count"])

# ボタンを押した数だけテキストが増える
st.subheader("2.ボタンを押した数だけテキストが増える")
if 'increasement' not in st.session_state:
  st.session_state["increasement"] = 0
  
if st.button("カウント", key=1):
  st.session_state["increasement"] += 1

for i in range(st.session_state["increasement"]):
  st.write(f"ボタンを押した回数 {i+1} 回目分")
  
# テキストフィールドに入力したテキストの追加ボタン、削除ボタンを設置。
st.subheader("3.テキストフィールドの文字が、追加ボタンを押すと増え、削除ボタンを押すと消える")
text = st.text_input("表示したい単語を入力してください")

if 'text_list' not in st.session_state:
  st.session_state["text_list"] = []

col1, col2 = st.columns(2)

with col1:
  if st.button("追加", key=2):
    st.session_state["text_list"].append(text)

with col2:
  if st.button("削除", key=3): 
    st.session_state["text_list"].remove(text)
      
for output_text in st.session_state["text_list"]:
  st.write("", output_text)
  
# 綺麗に並んだテキスト(行数の表示あり)3つが、追加ボタンを押すと増え、削除ボタンを押すと消える
st.subheader("4.綺麗に並んだテキスト(行数の表示あり)3つが、追加ボタンを押すと増え、削除ボタンを押すと消える")
if 'add_container' not in st.session_state:
  st.session_state["add_container"] = 0

col3, col4 = st.columns(2)

with col3:
  if st.button("追加", key=4):
    st.session_state["add_container"] += 1

with col4:
  if st.button("削除", key=5):
    if st.session_state["add_container"] >= 1:
      st.session_state["add_container"] -= 1


def add_container(row_num):
  with st.container():
    col1, col2, col3 = st.columns(3)
    
    with col1:
      st.write(f"This is left side in {row_num+1} row.")
      
    with col2:
      st.write(f"This is middle side in {row_num+1} row.")
      
    with col3:
      st.write(f"This is right side in {row_num+1} row.")
      
for i in range(st.session_state["add_container"]):
  add_container(i)
  
# ボタンを押すとヴィジェットを追加する
import uuid 

st.subheader("5.ボタンを押すとヴィジェットを追加する")

if 'unique_id' not in st.session_state:
  st.session_state["unique_id"] = []

col5, col6 = st.columns(2)

with col5:
  if st.button("追加", key=6):
    st.session_state["unique_id"].append(uuid.uuid1())

with col6:
  if st.button("削除", key=7):
    st.session_state["unique_id"].pop(-1)
    
for unique_id in st.session_state["unique_id"]:
  
  with st.container():
    col7, col8 = st.columns(2)

    with col7:
      slider_value = st.slider(
        "数値",
        min_value=0,
        max_value=14,
        value=0,
        key=unique_id
      )
    with col8:
      st.write("")
      st.write("")
      st.write(slider_value)