Repository: streamlit/streamlit

Issue:
New streamlit.beta_page_config
# Summary

I called streamlit.beta_page_config once at the beginning of the code, It works at start, but, when using slider in app, it reports the error:
`StreamlitAPIException: beta_set_page_config() can only be called once per app, and must be called as the first Streamlit command in your script.
`
# Steps to reproduce

What are the steps we should take to reproduce the bug:

1. Go to 'https://nimani.diplomacy.edu:8502/'
2. Click on 'Isolation Forest ' radio button from sidebar menu
3. try to change slider 'Contamination' on sidebar menu

## Expected behavior:

It should show updated plotly table

## Actual behavior:

It reports error:
`StreamlitAPIException: beta_set_page_config() can only be called once per app, and must be called as the first Streamlit command in your script.

## Is this a regression?

That is, did this use to work the way you expected in the past?
no, feature did not exist in earlier versions, since it is a new beta feature

# Debug info

- Streamlit version: 0.65.1
- Python version: 3.7.7
- Using Conda? PipEnv? PyEnv? Pex? No
- OS version: Ubuntu 18.04
- Browser version: Google Chrome, Version 84.0.4147.125

# Additional information

If needed, add any other context about the problem here. For example, did this bug come from https://discuss.streamlit.io or another site? Link the original source here!



Discussion:

Resolving patch:
diff --git a/lib/streamlit/report_thread.py b/lib/streamlit/report_thread.py
--- a/lib/streamlit/report_thread.py
+++ b/lib/streamlit/report_thread.py
@@ -58,7 +58,6 @@ def __init__(
         self.widgets = widgets
         self.widget_ids_this_run = widget_ids_this_run
         self.uploaded_file_mgr = uploaded_file_mgr
-
         # set_page_config is allowed at most once, as the very first st.command
         self._set_page_config_allowed = True
 
@@ -66,6 +65,8 @@ def reset(self, query_string=""):
         self.cursors = {}
         self.widget_ids_this_run.clear()
         self.query_string = query_string
+        # Permit set_page_config when the ReportContext is reused on a rerun
+        self._set_page_config_allowed = True
 
     def enqueue(self, msg):
         if msg.HasField("page_config_changed") and not self._set_page_config_allowed:


Test patch:
diff --git a/lib/tests/streamlit/report_context_test.py b/lib/tests/streamlit/report_context_test.py
--- a/lib/tests/streamlit/report_context_test.py
+++ b/lib/tests/streamlit/report_context_test.py
@@ -35,3 +35,19 @@ def test_set_page_config_first(self):
         ctx.enqueue(markdown_msg)
         with self.assertRaises(StreamlitAPIException):
             ctx.enqueue(msg)
+
+    def test_set_page_config_reset(self):
+        """st.set_page_config should be allowed after a rerun"""
+
+        fake_enqueue = lambda msg: None
+        ctx = ReportContext("TestSessionID", fake_enqueue, "", None, MagicMock(), None)
+
+        msg = ForwardMsg()
+        msg.page_config_changed.title = "foo"
+
+        ctx.enqueue(msg)
+        ctx.reset()
+        try:
+            ctx.enqueue(msg)
+        except StreamlitAPIException:
+            self.fail("set_page_config should have succeeded after reset!")