Make number_input display the same value after switching pages

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.