Streamlit is an open-source Python library that makes it easy to build beautiful custom web-apps for machine learning and data science.
Streamlit apps can be deployed with the
For Streamlit apps, the entrypoint is the name of the
Python file containing your app. For example, if your app's source
file is named
rsconnect deploy streamlit -n <saved server name> --entrypoint main.py ...
There are some Streamlit example apps available from the Streamlit developers:
To deploy one of these examples, first clone the repository:
git clone https://github.com/streamlit/<app-name>
Install any required dependencies. Test the app locally:
streamlit run <app-name>/streamlit_app.py
Then deploy to Posit Connect:
rsconnect deploy streamlit -n <saved server name> --entrypoint streamlit_app.py <app-name>/
You can retrieve the username and group information provided by Posit Connect using the following Streamlit code, in Streamlit versions up to 1.11. Streamlit 1.12 removed this feature.
import json try: # Streamlit 1.8 or newer from streamlit.scriptrunner import get_script_run_ctx except ImportError: from streamlit.script_run_context import get_script_run_ctx from streamlit.server.server import Server def get_user_info(): session_id = get_script_run_ctx().session_id session_info = Server.get_current()._get_session_info(session_id) if session_info is None: raise Exception("Couldn't get your Streamlit session.") user_info_json = session_info.ws.request.headers.get("Rstudio-Connect-Credentials") if user_info_json is None: return None return json.loads(user_info_json) def get_username(): user_info = get_user_info() if user_info is None: return None return user_info.get("user") st.write("Username: " + get_username())
User and Group uniqueness#
Most environments have unique usernames where each
user identifies a
single user and
groups the name of the groups the user is a member of.
However, in large organizations with hundreds of users and groups, this may not be true. See the Admin Guide sections Credentials for Content for more information.
- Posit Connect requires Streamlit v56.1 or higher.
- Streamlit versions starting with 0.57 require Bokeh 2.0 or higher.
- Streamlit versions prior to 0.57 require Bokeh 1.4.