whitphx HF staff commited on
Commit
2995911
β€’
1 Parent(s): 4ea7774

Set consistent keys

Browse files

With the current script where the component keys change randomly upon each run, the component values are reset immediately after the user interacts the widgets on the page.
To fix it, we should make the component keys consistent across the script runs.

Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -29,7 +29,7 @@ st.image(
29
 
30
  """
31
  # Try out Theming!
32
- Click on the images below to view this app with different themes.
33
  """
34
 
35
  ""
@@ -90,9 +90,9 @@ def draw_all(
90
  st.write(
91
  """
92
  # Example Widgets
93
-
94
- These widgets don't do anything. But look at all the new colors they got πŸ‘€
95
-
96
  ```python
97
  # First some code.
98
  streamlit = "cool"
@@ -102,13 +102,13 @@ def draw_all(
102
  """
103
  )
104
 
105
- st.checkbox("Is this cool or what?", key=str(random.randint(0, 10000)))
106
  st.radio(
107
  "How many balloons?",
108
  ["1 balloon 🎈", "2 balloons 🎈🎈", "3 balloons 🎈🎈🎈"],
109
- key=str(random.randint(0, 10000)),
110
  )
111
- st.button("🀑 Click me", key=str(random.randint(0, 10000)))
112
 
113
  # if plot:
114
  # st.write("Oh look, a plot:")
@@ -123,18 +123,18 @@ def draw_all(
123
 
124
  # st.plotly_chart(fig, use_container_width=True)
125
 
126
- st.file_uploader("You can now upload with style", key=str(random.randint(0, 10000)))
127
  st.slider(
128
- "From 10 to 11, how cool are themes?", min_value=10, max_value=11, key=str(random.randint(0, 10000))
129
  )
130
  # st.select_slider("Pick a number", [1, 2, 3], key=key)
131
- st.number_input("So many numbers", key=str(random.randint(0, 10000)))
132
- st.text_area("A little writing space for you :)", key=str(random.randint(0, 10000)))
133
- st.text_input("Text input :)", key=str(random.randint(0, 10000)))
134
  st.selectbox(
135
  "My favorite thing in the world is...",
136
  ["Streamlit", "Theming", "Baloooons 🎈 "],
137
- key=str(random.randint(0, 10000)),
138
  )
139
  # st.multiselect("Pick a number", [1, 2, 3], key=key)
140
  # st.color_picker("Colors, colors, colors", key=key)
 
29
 
30
  """
31
  # Try out Theming!
32
+ Click on the images below to view this app with different themes.
33
  """
34
 
35
  ""
 
90
  st.write(
91
  """
92
  # Example Widgets
93
+
94
+ These widgets don't do anything. But look at all the new colors they got πŸ‘€
95
+
96
  ```python
97
  # First some code.
98
  streamlit = "cool"
 
102
  """
103
  )
104
 
105
+ st.checkbox("Is this cool or what?", key=key+":checkbox")
106
  st.radio(
107
  "How many balloons?",
108
  ["1 balloon 🎈", "2 balloons 🎈🎈", "3 balloons 🎈🎈🎈"],
109
+ key=key+":radio",
110
  )
111
+ st.button("🀑 Click me", key=key+":button")
112
 
113
  # if plot:
114
  # st.write("Oh look, a plot:")
 
123
 
124
  # st.plotly_chart(fig, use_container_width=True)
125
 
126
+ st.file_uploader("You can now upload with style", key=key+":file_uploader")
127
  st.slider(
128
+ "From 10 to 11, how cool are themes?", min_value=10, max_value=11, key=key+":slider"
129
  )
130
  # st.select_slider("Pick a number", [1, 2, 3], key=key)
131
+ st.number_input("So many numbers", key=key+":number_input")
132
+ st.text_area("A little writing space for you :)", key=key+":text_area")
133
+ st.text_input("Text input :)", key=key+":text_input")
134
  st.selectbox(
135
  "My favorite thing in the world is...",
136
  ["Streamlit", "Theming", "Baloooons 🎈 "],
137
+ key=key+":selectbox",
138
  )
139
  # st.multiselect("Pick a number", [1, 2, 3], key=key)
140
  # st.color_picker("Colors, colors, colors", key=key)