Skip to content

Commit 5c680e0

Browse files
authoredJan 30, 2024
Prerelease 1.31.0 - Embedded app management (#946)
* Update page_link example source * Add chat_input inline example * Add write_stream example source * Ignore secrets * Correct file names * Add custom navigation example * Ignore all __pycache__ * Switch to nightly * Add check for None in custom navigation example
1 parent 5b8cb26 commit 5c680e0

File tree

16 files changed

+134
-7
lines changed

16 files changed

+134
-7
lines changed
 

‎.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typings/
6060
.rts2_cache_umd/
6161

6262
# Python cache
63-
python/__pycache__/
63+
__pycache__
6464

6565
# Optional REPL history
6666
.node_repl_history
@@ -112,4 +112,5 @@ node_modules/
112112
.DS_Store
113113
out/
114114
public/pdf/pages/
115-
.idea/
115+
.idea/
116+
python/api-examples-source/.streamlit/secrets.toml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import streamlit as st
2+
3+
with st.sidebar:
4+
prompt = st.chat_input("Say something")
5+
if prompt:
6+
st.write(f"User has sent the following prompt: {prompt}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import streamlit as st
2+
3+
long_text = "Lorem ipsum. " * 1000
4+
5+
with st.container(height=300):
6+
st.markdown(long_text)

‎python/api-examples-source/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ altair==4.2.0
1010
pydeck==0.8.0
1111
Faker==19.1.0
1212
openai==1.3.0
13-
streamlit==1.30.0
13+
streamlit-nightly
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import time
2+
import numpy as np
3+
import pandas as pd
4+
import streamlit as st
5+
6+
_LOREM_IPSUM = """
7+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
8+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
9+
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
10+
"""
11+
12+
13+
def stream_data():
14+
for word in _LOREM_IPSUM.split():
15+
yield word + " "
16+
time.sleep(0.02)
17+
18+
yield pd.DataFrame(
19+
np.random.randn(5, 10),
20+
columns=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
21+
)
22+
23+
for word in _LOREM_IPSUM.split():
24+
yield word + " "
25+
time.sleep(0.02)
26+
27+
28+
if st.button("Stream data"):
29+
st.write_stream(stream_data)
30+
st.title("Hi inside the button")
31+
32+
st.title("Hi outside the button")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[client]
2+
showSidebarNavigation = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import streamlit as st
2+
from menu import menu
3+
4+
if "role" in st.session_state:
5+
st.session_state._role = st.session_state.role
6+
else:
7+
st.session_state.role = None
8+
9+
10+
def set_role():
11+
st.session_state.role = st.session_state._role
12+
13+
14+
st.selectbox(
15+
"Select your role:",
16+
[None, "user", "admin", "super-admin"],
17+
key="_role",
18+
on_change=set_role,
19+
)
20+
menu()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import streamlit as st
2+
3+
4+
def logged_in():
5+
st.sidebar.page_link("app.py", label="Switch accounts")
6+
st.sidebar.page_link("pages/user.py", label="Your profile")
7+
if st.session_state.role in ["admin", "super-admin"]:
8+
st.sidebar.page_link("pages/admin.py", label="Manage users")
9+
st.sidebar.page_link(
10+
"pages/super-admin.py",
11+
label="Manage admin access",
12+
disabled=st.session_state.role != "super-admin",
13+
)
14+
15+
16+
def not_logged_in():
17+
st.sidebar.page_link("app.py", label="Log in")
18+
19+
20+
def menu():
21+
if "role" not in st.session_state or st.session_state.role is None:
22+
not_logged_in()
23+
return
24+
logged_in()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import streamlit as st
2+
from menu import menu
3+
4+
if "role" not in st.session_state or st.session_state.role is None:
5+
st.switch_page("app.py")
6+
menu()
7+
8+
if st.session_state.role not in ["admin", "super-admin"]:
9+
st.warning("You do not have permission to view this page.")
10+
st.stop()
11+
12+
st.title("This page is available to all admins")
13+
14+
st.markdown(f"You are currently logged with the role of {st.session_state.role}.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import streamlit as st
2+
from menu import menu
3+
4+
if "role" not in st.session_state or st.session_state.role is None:
5+
st.switch_page("app.py")
6+
menu()
7+
8+
if st.session_state.role not in ["super-admin"]:
9+
st.warning("You do not have permission to view this page.")
10+
st.stop()
11+
12+
st.title("This page is available to super-admins")
13+
st.markdown(f"You are currently logged with the role of {st.session_state.role}.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import streamlit as st
2+
from menu import menu
3+
4+
if "role" not in st.session_state or st.session_state.role is None:
5+
st.switch_page("app.py")
6+
menu()
7+
8+
st.title("This page is available to all users")
9+
st.markdown(f"You are currently logged with the role of {st.session_state.role}.")
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
streamlit==1.30.0
1+
streamlit-nightly

‎python/api-examples-source/widgets.page_link/pages/page_1.py ‎python/api-examples-source/widget.page_link/pages/page_1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
st.page_link("your_app.py", label="Home", icon="🏠")
44
st.page_link("pages/page_1.py", label="Page 1", icon="1️⃣")
5-
st.page_link("pages/page_2.py", label="Page 2", icon="2️⃣")
5+
st.page_link("pages/page_2.py", label="Page 2", icon="2️⃣", disabled=True)
66
st.page_link("http://www.google.com", label="Google", icon="🌎")

‎python/api-examples-source/widgets.page_link/pages/page_2.py ‎python/api-examples-source/widget.page_link/pages/page_2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
st.page_link("your_app.py", label="Home", icon="🏠")
44
st.page_link("pages/page_1.py", label="Page 1", icon="1️⃣")
5-
st.page_link("pages/page_2.py", label="Page 2", icon="2️⃣")
5+
st.page_link("pages/page_2.py", label="Page 2", icon="2️⃣", disabled=True)
66
st.page_link("http://www.google.com", label="Google", icon="🌎")

‎python/api-examples-source/widgets.page_link/your_app.py ‎python/api-examples-source/widget.page_link/your_app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
st.page_link("your_app.py", label="Home", icon="🏠")
44
st.page_link("pages/page_1.py", label="Page 1", icon="1️⃣")
5-
st.page_link("pages/page_2.py", label="Page 2", icon="2️⃣")
5+
st.page_link("pages/page_2.py", label="Page 2", icon="2️⃣", disabled=True)
66
st.page_link("http://www.google.com", label="Google", icon="🌎")

0 commit comments

Comments
 (0)