Skip to content

Commit 37e95f5

Browse files
Update example in button guide (#1214)
Former-commit-id: a1f5864
1 parent 5f8ee02 commit 37e95f5

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

content/develop/concepts/app-design/button-behavior-and-examples.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,8 @@ if 'processed' not in st.session_state:
365365
if st.button('Process'):
366366
result = expensive_process(option, add)
367367
st.session_state.processed[option] = result
368-
369-
if option in st.session_state.processed:
370368
st.write(f'Option {option} processed with add {add}')
371-
st.write(st.session_state.processed[option][0])
369+
result[0]
372370
```
373371

374372
Astute observers may think, "This feels a little like caching." We are only saving results relative to one parameter, but the pattern could easily be expanded to save results relative to both parameters. In that sense, yes, it has some similarities to caching, but also some important differences. When you save results in `st.session_state`, the results are only available to the current user in their current session. If you use [`st.cache_data`](/develop/api-reference/caching-and-state/st.cache_data) instead, the results are available to all users across all sessions. Furthermore, if you want to update a saved result, you have to clear all saved results for that function to do so.

0 commit comments

Comments
 (0)