Make number_input display the same value after switching pages

So I’m making a multipaged app in Streamlit, and the number input from the previous page gets used on the other one. I was wondering if there was a way to make sure number input still displays the saved data, because once I leave the page and come back, the number_input gives me 0. I’m really confused with session_state still, so anything will help! I think part of the issue is that I’m using session_state on the dictionaries I’m putting all of my variables in, and no the variables themselves.

Summary: I want my number_input to still display the user’s input number after I leave the page.
num input problem

The important thing to understand is that widget information is deleted whenever a widget is not continuously rendered. This can happen by changing pages or even by conditionally not rendering the widget on the same page.

There are two workarounds to preserve widget values across pages, both require using a key with your widget:

  1. Use a dummy-key to separate a value you want to keep in session state persistently from a value Streamlit associates to a widget (and automatically deletes).
  2. Recommit keys to session state at the top of every page.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.