Thanks to everyone trying to help!
The issue with executing the Streamlit code in an IDE is not IDE-dependent (also tried VSCode and Jupyter). It seems to be rather associated with the session state processing not done by IDE, as noted here. However, I am still struggling to adapt the proposed solution to the simple example code, and any suggestions would be appreciated.
Also, the general topic of using IDEs for Streamlit code development and debugging does not seem to be well covered in the documentation.