def experimental_set_query_params(**query_params): """Set the query parameters that are shown in the browser's URL bar. Parameters ---------- **query_params : dict The query parameters to set, as key-value pairs. Example ------- To point the user's web browser to something like "http://localhost:8501/?show_map=True&selected=asia&selected=america", you would do the following: >>> st.experimental_set_query_params( ... show_map=True, ... selected=["asia", "america"], ... ) """ ctx = _get_report_ctx() if ctx is None: return ctx.query_string = _parse.urlencode(query_params, doseq=True) msg = _ForwardMsg_pb2.ForwardMsg() msg.page_info_changed.query_string = ctx.query_string ctx.enqueue(msg)
def experimental_get_query_params(): """Return the query parameters that is currently showing in the browser's URL bar. Returns ------- dict The current query parameters as a dict. "Query parameters" are the part of the URL that comes after the first "?". Example ------- Let's say the user's web browser is at `http://localhost:8501/?show_map=True&selected=asia&selected=america`. Then, you can get the query parameters using the following: >>> st.experimental_get_query_params() {"show_map": ["True"], "selected": ["asia", "america"]} Note that the values in the returned dict are *always* lists. This is because we internally use Python's urllib.parse.parse_qs(), which behaves this way. And this behavior makes sense when you consider that every item in a query string is potentially a 1-element array. """ ctx = _get_report_ctx() if ctx is None: return "" return _parse.parse_qs(ctx.query_string)
def experimental_rerun(): """Rerun the script immediately. When `st.experimental_rerun()` is called, the script is halted - no more statements will be run, and the script will be queued to re-run from the top. If this function is called outside of Streamlit, it will raise an Exception. """ ctx = _get_report_ctx() query_string = None if ctx is None else ctx.query_string raise _RerunException(_RerunData(query_string=query_string))