Skip to content

Commit

Permalink
Prerelease 1.40.0: Embedded examples (#1179)
Browse files Browse the repository at this point in the history
* Bump to nightly

* Audio input GA

* Button groups

* Navigation examples
  • Loading branch information
sfc-gh-dmatthews authored Nov 1, 2024
1 parent 918606d commit 7246208
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 2 deletions.
3 changes: 3 additions & 0 deletions python/api-examples-source/navigation.example_1/Page_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import streamlit as st

st.title("Page 1")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
streamlit-nightly
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import streamlit as st

def Page_2():
st.title("Page 2")

pg = st.navigation([st.Page("Page_1.py"), st.Page(Page_2)])
pg.run()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import streamlit as st

st.title("Create your account")
3 changes: 3 additions & 0 deletions python/api-examples-source/navigation.example_2/learn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import streamlit as st

st.title("Learn about us")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import streamlit as st

st.title("Manage your account")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
streamlit-nightly
15 changes: 15 additions & 0 deletions python/api-examples-source/navigation.example_2/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import streamlit as st

pages = {
"Your account": [
st.Page("create_account.py", title="Create your account"),
st.Page("manage_account.py", title="Manage your account"),
],
"Resources": [
st.Page("learn.py", title="Learn about us"),
st.Page("trial.py", title="Try it out"),
],
}

pg = st.navigation(pages)
pg.run()
3 changes: 3 additions & 0 deletions python/api-examples-source/navigation.example_2/trial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import streamlit as st

st.title("Try it out")
14 changes: 14 additions & 0 deletions python/api-examples-source/navigation.multipage_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import streamlit as st

def page1():
st.write(st.session_state.foo)

def page2():
st.write(st.session_state.bar)

# Widgets shared by all the pages
st.sidebar.selectbox("Foo", ["A", "B", "C"], key="foo")
st.sidebar.checkbox("Bar", key="bar")

pg = st.navigation([st.Page(page1), st.Page(page2)])
pg.run()
2 changes: 1 addition & 1 deletion python/api-examples-source/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pydeck
Faker
openai
vega_datasets
streamlit>=1.39.0
streamlit-nightly
2 changes: 1 addition & 1 deletion python/api-examples-source/widget.audio_input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import streamlit as st

audio_value = st.experimental_audio_input("Record a voice message")
audio_value = st.audio_input("Record a voice message")

if audio_value:
st.audio(audio_value)
9 changes: 9 additions & 0 deletions python/api-examples-source/widget.pills_multi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import streamlit as st

options = ["North", "East", "South", "West"]
selection = st.pills(
"Directions",
options,
selection_mode="multi"
)
st.markdown(f"Your selected options: {selection}.")
18 changes: 18 additions & 0 deletions python/api-examples-source/widget.pills_single.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import streamlit as st

option_map = {
0: ":material/add:",
1: ":material/zoom_in:",
2: ":material/zoom_out:",
3: ":material/zoom_out_map:",
}
selection = st.pills(
"Tool",
options=option_map.keys(),
format_func=lambda option: option_map[option],
selection_mode="single",
)
st.write(
"Your selected option: "
f"{None if selection is None else option_map[selection]}"
)
9 changes: 9 additions & 0 deletions python/api-examples-source/widget.segmented_control_multi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import streamlit as st

options = ["North", "East", "South", "West"]
selection = st.segmented_control(
"Directions",
options,
selection_mode="multi"
)
st.markdown(f"Your selected options: {selection}.")
18 changes: 18 additions & 0 deletions python/api-examples-source/widget.segmented_control_single.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import streamlit as st

option_map = {
0: ":material/add:",
1: ":material/zoom_in:",
2: ":material/zoom_out:",
3: ":material/zoom_out_map:",
}
selection = st.segmented_control(
"Tool",
options=option_map.keys(),
format_func=lambda option: option_map[option],
selection_mode="single",
)
st.write(
"Your selected option: "
f"{None if selection is None else option_map[selection]}"
)

0 comments on commit 7246208

Please sign in to comment.