diff --git a/pages/charts.area_chart.py b/pages/charts.area_chart.py index 0e52bb743d5044a7b7b696005426554eddb33a7e..0eed64286e7238186572dc39e3d9965023170d2a 100644 --- a/pages/charts.area_chart.py +++ b/pages/charts.area_chart.py @@ -1,12 +1,16 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): - df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"]) + df = pd.DataFrame( + np.random.randn(20, 3), + columns = ['a', 'b', 'c']) return df + chart_data = load_data() st.area_chart(chart_data) diff --git a/pages/charts.area_chart1.py b/pages/charts.area_chart1.py new file mode 100644 index 0000000000000000000000000000000000000000..c33c9730e8154db24d12b8a651f7ad553fe728ab --- /dev/null +++ b/pages/charts.area_chart1.py @@ -0,0 +1,23 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + df = pd.DataFrame({ + 'col1' : np.random.randn(20), + 'col2' : np.random.randn(20), + 'col3' : np.random.choice(['A','B','C'], 20) + }) + return df + + +chart_data = load_data() + +st.area_chart( + chart_data, + x = 'col1', + y = 'col2', + color = 'col3' +) diff --git a/pages/charts.area_chart2.py b/pages/charts.area_chart2.py new file mode 100644 index 0000000000000000000000000000000000000000..507deb3963ae2987c9406ba34b86253aff27c271 --- /dev/null +++ b/pages/charts.area_chart2.py @@ -0,0 +1,21 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + df = pd.DataFrame( + np.random.randn(20, 3), + columns = ['col1', 'col2', 'col3']) + return df + + +chart_data = load_data() + +st.area_chart( + chart_data, + x = 'col1', + y = ['col2', 'col3'], + color = ['#FF0000', '#0000FF'] # Optional +) diff --git a/pages/charts.audio.py b/pages/charts.audio.py index de5adacf8d43f5420d808e324e0e4ebd2d089fd2..277deb9d8c39bb291e20bca592fc33dbea94f0cc 100644 --- a/pages/charts.audio.py +++ b/pages/charts.audio.py @@ -1,8 +1,9 @@ +import numpy as np import requests import streamlit as st -@st.experimental_memo +@st.cache_data def read_file_from_url(url): headers = { "User-Agent": "StreamlitDocs/1.5.0 (https://docs.streamlit.io; hello@streamlit.io)" @@ -32,3 +33,34 @@ st.write( """ ) + +st.code( + """ +import streamlit as st +import numpy as np + +sample_rate = 44100 # 44100 samples per second +seconds = 2 # Note duration of 2 seconds + +frequency_la = 440 # Our played note will be 440 Hz + +# Generate array with seconds*sample_rate steps, ranging between 0 and seconds +t = np.linspace(0, seconds, seconds * sample_rate, False) + +# Generate a 440 Hz sine wave +note_la = np.sin(frequency_la * t * 2 * np.pi) +st.audio(note_la, sample_rate=sample_rate) +""" +) + +sample_rate = 44100 # 44100 samples per second +seconds = 2 # Note duration of 2 seconds + +frequency_la = 440 # Our played note will be 440 Hz + +# Generate array with seconds*sample_rate steps, ranging between 0 and seconds +t = np.linspace(0, seconds, seconds * sample_rate, False) + +# Generate a 440 Hz sine wave +note_la = np.sin(frequency_la * t * 2 * np.pi) +st.audio(note_la, sample_rate=sample_rate) diff --git a/pages/charts.bar_chart.py b/pages/charts.bar_chart.py index 583a5e0ef57181a4f8b5b77a66873222062fd87f..07dfd2592e569bb35553dafce9181fa2de37e1b5 100644 --- a/pages/charts.bar_chart.py +++ b/pages/charts.bar_chart.py @@ -1,12 +1,16 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): - df = pd.DataFrame(np.random.randn(50, 3), columns=["a", "b", "c"]) + df = pd.DataFrame( + np.random.randn(50, 3), + columns = ["a", "b", "c"]) return df + chart_data = load_data() st.bar_chart(chart_data) diff --git a/pages/charts.bar_chart1.py b/pages/charts.bar_chart1.py new file mode 100644 index 0000000000000000000000000000000000000000..0807cfe414557e0455196297ba1343a9037abdd3 --- /dev/null +++ b/pages/charts.bar_chart1.py @@ -0,0 +1,23 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + df = pd.DataFrame({ + 'col1' : list(range(20))*3, + 'col2' : np.random.randn(60), + 'col3' : ['A']*20 + ['B']*20 + ['C']*20 + }) + return df + + +chart_data = load_data() + +st.bar_chart( + chart_data, + x = 'col1', + y = 'col2', + color = 'col3' +) diff --git a/pages/charts.bar_chart2.py b/pages/charts.bar_chart2.py new file mode 100644 index 0000000000000000000000000000000000000000..c56585305330ff25c5b6872dbb2973856c1cb87e --- /dev/null +++ b/pages/charts.bar_chart2.py @@ -0,0 +1,23 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + df = pd.DataFrame({ + 'col1' : list(range(20)), + 'col2' : np.random.randn(20), + 'col3' : np.random.randn(20) + }) + return df + + +chart_data = load_data() + +st.bar_chart( + chart_data, + x = 'col1', + y = ['col2', 'col3'], + color = ['#FF0000', '#0000FF'] # Optional +) diff --git a/pages/charts.graphviz_chart.py b/pages/charts.graphviz_chart.py index 5f21ba30492e813135f7cc8a68d391f62d19dde7..6ae8e2ea5b35d45e0055869ff029ea946b0e293d 100644 --- a/pages/charts.graphviz_chart.py +++ b/pages/charts.graphviz_chart.py @@ -1,7 +1,8 @@ -import streamlit as st import graphviz as graphviz +import streamlit as st -@st.experimental_memo + +@st.cache_data def load_graph(): # Create a graphlib graph object graph = graphviz.Digraph() @@ -20,6 +21,7 @@ def load_graph(): graph.edge("sleep", "runmem") return graph + graph = load_graph() st.graphviz_chart(graph) diff --git a/pages/charts.line_chart.py b/pages/charts.line_chart.py index 96b3c8d7070b134b903493f01ea6933529367bd8..07dfd8c761d1ff7c2662361466865d3a448de50e 100644 --- a/pages/charts.line_chart.py +++ b/pages/charts.line_chart.py @@ -1,12 +1,16 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st -@st.experimental_memo + +@st.cache_data def load_data(): - df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"]) + df = pd.DataFrame( + np.random.randn(20, 3), + columns = ['a', 'b', 'c']) return df - + + chart_data = load_data() st.line_chart(chart_data) diff --git a/pages/charts.line_chart1.py b/pages/charts.line_chart1.py new file mode 100644 index 0000000000000000000000000000000000000000..073a5f3b3cb74d58f3f52f8fea77e180b385c8ba --- /dev/null +++ b/pages/charts.line_chart1.py @@ -0,0 +1,23 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + df = pd.DataFrame({ + 'col1' : np.random.randn(20), + 'col2' : np.random.randn(20), + 'col3' : np.random.choice(['A','B','C'], 20) + }) + return df + + +chart_data = load_data() + +st.line_chart( + chart_data, + x = 'col1', + y = 'col2', + color = 'col3' +) diff --git a/pages/charts.line_chart2.py b/pages/charts.line_chart2.py new file mode 100644 index 0000000000000000000000000000000000000000..09f7ac51dca0faf8d4f9b1b93c91e2188aab1020 --- /dev/null +++ b/pages/charts.line_chart2.py @@ -0,0 +1,21 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + df = pd.DataFrame( + np.random.randn(20, 3), + columns = ['col1', 'col2', 'col3']) + return df + + +chart_data = load_data() + +st.line_chart( + chart_data, + x = 'col1', + y = ['col2', 'col3'], + color = ['#FF0000', '#0000FF'] # Optional +) diff --git a/pages/charts.map.py b/pages/charts.map.py index 5ef2b2cfcc355f45effad31a509ca9c185c13c45..8d214cb9966e928fd44c4e2d71432da3bf6745c8 100644 --- a/pages/charts.map.py +++ b/pages/charts.map.py @@ -1,14 +1,16 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): df = pd.DataFrame( np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"] ) return df + df = load_data() st.map(df) diff --git a/pages/charts.map_color.py b/pages/charts.map_color.py new file mode 100644 index 0000000000000000000000000000000000000000..e30c6361f36cce1db4219e7e3e10309748e872ea --- /dev/null +++ b/pages/charts.map_color.py @@ -0,0 +1,20 @@ +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "col1": np.random.randn(1000) / 50 + 37.76, + "col2": np.random.randn(1000) / 50 + -122.4, + "col3": np.random.randn(1000) * 100, + "col4": np.random.rand(1000, 4).tolist(), + } + ) + + +df = load_data() + +st.map(df, latitude="col1", longitude="col2", size="col3", color="col4") diff --git a/pages/charts.plotly_chart.py b/pages/charts.plotly_chart.py index fa5e38175a2f7d4a222410e50c5e88818c97056c..bf0ce0bc39b1bc110bd119c41e7d7db24f3156d1 100644 --- a/pages/charts.plotly_chart.py +++ b/pages/charts.plotly_chart.py @@ -1,8 +1,9 @@ -import streamlit as st -import plotly.figure_factory as ff import numpy as np +import plotly.figure_factory as ff +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): # Add histogram data x1 = np.random.randn(200) - 2 @@ -13,6 +14,7 @@ def load_data(): hist_data = [x1, x2, x3] return hist_data + hist_data = load_data() group_labels = ["Group 1", "Group 2", "Group 3"] diff --git a/pages/charts.pydeck_chart.py b/pages/charts.pydeck_chart.py index 1b35a0dc59bbbb4fc274466d28c6377226593a25..7027ed8351264cb016f5ceaeabeb8ea09e178ced 100644 --- a/pages/charts.pydeck_chart.py +++ b/pages/charts.pydeck_chart.py @@ -4,7 +4,7 @@ import pydeck as pdk import streamlit as st -@st.experimental_memo +@st.cache_data def load_data(): return pd.DataFrame( np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"] diff --git a/pages/charts.pyplot.py b/pages/charts.pyplot.py index 2de00204bfdf5c7d9bbf80176c41df1489ce0acb..d0c03c04f7836ae64a5091b1c226385977b10ea9 100644 --- a/pages/charts.pyplot.py +++ b/pages/charts.pyplot.py @@ -1,14 +1,16 @@ -import streamlit as st -import numpy as np import matplotlib.pyplot as plt +import numpy as np +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_fig(): arr = np.random.normal(1, 1, size=100) fig, ax = plt.subplots() ax.hist(arr, bins=20) return fig, ax + fig, ax = load_fig() st.pyplot(fig) diff --git a/pages/charts.vega_lite_chart.py b/pages/charts.vega_lite_chart.py index c0d0983cfd55788b5976402e812ca4c096b3d4bf..b6d0c642d2ae9fe9c65ff6e9858069d25113d936 100644 --- a/pages/charts.vega_lite_chart.py +++ b/pages/charts.vega_lite_chart.py @@ -1,12 +1,14 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): df = pd.DataFrame(np.random.randn(200, 3), columns=["a", "b", "c"]) return df + df = load_data() st.vega_lite_chart( diff --git a/pages/chat.echo.py b/pages/chat.echo.py new file mode 100644 index 0000000000000000000000000000000000000000..55e70ebe4e2b994e9afe1b2fff4d16a08dc6c5e9 --- /dev/null +++ b/pages/chat.echo.py @@ -0,0 +1,26 @@ +import streamlit as st + +st.title("Echo Bot") + +# Initialize chat history +if "messages" not in st.session_state: + st.session_state.messages = [] + +# Display chat messages from history on app rerun +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# React to user input +if prompt := st.chat_input("What is up?"): + # Display user message in chat message container + st.chat_message("user").markdown(prompt) + # Add user message to chat history + st.session_state.messages.append({"role": "user", "content": prompt}) + + response = f"Echo: {prompt}" + # Display assistant response in chat message container + with st.chat_message("assistant"): + st.markdown(response) + # Add assistant response to chat history + st.session_state.messages.append({"role": "assistant", "content": response}) diff --git a/pages/chat.input.py b/pages/chat.input.py new file mode 100644 index 0000000000000000000000000000000000000000..31ffcd4b80b6152fe2170f424d817c17c7314c90 --- /dev/null +++ b/pages/chat.input.py @@ -0,0 +1,5 @@ +import streamlit as st + +prompt = st.chat_input("Say something") +if prompt: + st.write(f"User has sent the following prompt: {prompt}") diff --git a/pages/chat.llm.py b/pages/chat.llm.py new file mode 100644 index 0000000000000000000000000000000000000000..fcdb7804bb577c77b54f9b7d7e552e433b372a44 --- /dev/null +++ b/pages/chat.llm.py @@ -0,0 +1,57 @@ +import openai +import streamlit as st + +st.title("ChatGPT-like clone") +with st.expander("ℹī¸ Disclaimer"): + st.caption( + "We appreciate your engagement! Please note, this demo is designed to process a maximum of 10 interactions. Thank you for your understanding." + ) + +openai.api_key = st.secrets["OPENAI_API_KEY"] + +if "openai_model" not in st.session_state: + st.session_state["openai_model"] = "gpt-3.5-turbo" + +if "messages" not in st.session_state: + st.session_state.messages = [] + +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Maximum allowed messages +max_messages = ( + 20 # Counting both user and assistant messages, so 10 iterations of conversation +) + +if len(st.session_state.messages) >= max_messages: + st.info( + """Notice: The maximum message limit for this demo version has been reached. We value your interest! + We encourage you to experience further interactions by building your own application with instructions + from Streamlit's [Build conversational apps](https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps) + tutorial. Thank you for your understanding.""" + ) + +else: + if prompt := st.chat_input("What is up?"): + st.session_state.messages.append({"role": "user", "content": prompt}) + with st.chat_message("user"): + st.markdown(prompt) + + with st.chat_message("assistant"): + message_placeholder = st.empty() + full_response = "" + for response in openai.ChatCompletion.create( + model=st.session_state["openai_model"], + messages=[ + {"role": m["role"], "content": m["content"]} + for m in st.session_state.messages + ], + stream=True, + ): + full_response += response.choices[0].delta.get("content", "") + message_placeholder.markdown(full_response + "▌") + message_placeholder.markdown(full_response) + st.session_state.messages.append( + {"role": "assistant", "content": full_response} + ) diff --git a/pages/chat.message.py b/pages/chat.message.py new file mode 100644 index 0000000000000000000000000000000000000000..f644ae62af9b8b822aeb97295de4c44b9350d976 --- /dev/null +++ b/pages/chat.message.py @@ -0,0 +1,6 @@ +import numpy as np +import streamlit as st + +with st.chat_message("user"): + st.write("Hello 👋") + st.line_chart(np.random.randn(30, 3)) diff --git a/pages/chat.message1.py b/pages/chat.message1.py new file mode 100644 index 0000000000000000000000000000000000000000..4b3ac79b3d49a80e1bf6fbebd1cc15ba9456fefa --- /dev/null +++ b/pages/chat.message1.py @@ -0,0 +1,6 @@ +import numpy as np +import streamlit as st + +message = st.chat_message("assistant") +message.write("Hello human") +message.bar_chart(np.random.randn(30, 3)) diff --git a/pages/chat.simple.py b/pages/chat.simple.py new file mode 100644 index 0000000000000000000000000000000000000000..72b1683aa38263ac77077085be828c19d3b34866 --- /dev/null +++ b/pages/chat.simple.py @@ -0,0 +1,44 @@ +import random +import time + +import streamlit as st + +st.title("Simple chat") + +# Initialize chat history +if "messages" not in st.session_state: + st.session_state.messages = [] + +# Display chat messages from history on app rerun +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Accept user input +if prompt := st.chat_input("What is up?"): + # Add user message to chat history + st.session_state.messages.append({"role": "user", "content": prompt}) + # Display user message in chat message container + with st.chat_message("user"): + st.markdown(prompt) + + # Display assistant response in chat message container + with st.chat_message("assistant"): + message_placeholder = st.empty() + full_response = "" + assistant_response = random.choice( + [ + "Hello there! How can I assist you today?", + "Hi, human! Is there anything I can help you with?", + "Do you need help?", + ] + ) + # Simulate stream of response with milliseconds delay + for chunk in assistant_response.split(): + full_response += chunk + " " + time.sleep(0.05) + # Add a blinking cursor to simulate typing + message_placeholder.markdown(full_response + "▌") + message_placeholder.markdown(full_response) + # Add assistant response to chat history + st.session_state.messages.append({"role": "assistant", "content": full_response}) diff --git a/pages/data.barchart_column.py b/pages/data.barchart_column.py new file mode 100644 index 0000000000000000000000000000000000000000..b15b74f6df107aa94f5e232c9124ec70b1e61a8c --- /dev/null +++ b/pages/data.barchart_column.py @@ -0,0 +1,32 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "sales": [ + [0, 4, 26, 80, 100, 40], + [80, 20, 80, 35, 40, 100], + [10, 20, 80, 80, 70, 0], + [10, 100, 20, 100, 30, 100], + ], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "sales": st.column_config.BarChartColumn( + "Sales (last 6 months)", + help="The sales volume in the last 6 months", + y_min=0, + y_max=100, + ), + }, + hide_index=True, +) diff --git a/pages/data.checkbox_column.py b/pages/data.checkbox_column.py new file mode 100644 index 0000000000000000000000000000000000000000..fdab125f97b9308c08e3ba06d87b4a53f8ad8c7e --- /dev/null +++ b/pages/data.checkbox_column.py @@ -0,0 +1,28 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "widgets": ["st.selectbox", "st.number_input", "st.text_area", "st.button"], + "favorite": [True, False, False, True], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "favorite": st.column_config.CheckboxColumn( + "Your favorite?", + help="Select your **favorite** widgets", + default=False, + ) + }, + disabled=["widgets"], + hide_index=True, +) diff --git a/pages/data.column.py b/pages/data.column.py new file mode 100644 index 0000000000000000000000000000000000000000..589363c3b97f7189a5d33cb33865c35b3acbf969 --- /dev/null +++ b/pages/data.column.py @@ -0,0 +1,28 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "widgets": ["st.selectbox", "st.number_input", "st.text_area", "st.button"], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "widgets": st.column_config.Column( + "Streamlit Widgets", + help="Streamlit **widget** commands 🎈", + width="medium", + required=True, + ) + }, + hide_index=True, + num_rows="dynamic", +) diff --git a/pages/data.column_config.empty.py b/pages/data.column_config.empty.py new file mode 100644 index 0000000000000000000000000000000000000000..acd0ce3637c30af173f73ccedb4938d549807f36 --- /dev/null +++ b/pages/data.column_config.empty.py @@ -0,0 +1,15 @@ +import streamlit as st +import pandas as pd + +df = pd.DataFrame(columns=['name','age','color']) +colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] +config = { + 'name' : st.column_config.TextColumn('Full Name (required)', width='large', required=True), + 'age' : st.column_config.NumberColumn('Age (years)', min_value=0, max_value=122), + 'color' : st.column_config.SelectboxColumn('Favorite Color', options=colors) +} + +result = st.data_editor(df, column_config = config, num_rows='dynamic') + +if st.button('Get results'): + st.write(result) diff --git a/pages/data.column_config.py b/pages/data.column_config.py new file mode 100644 index 0000000000000000000000000000000000000000..251b04f249e77dc6e76f1c891acedb85967888df --- /dev/null +++ b/pages/data.column_config.py @@ -0,0 +1,103 @@ +import random +from datetime import date + +import numpy as np +import pandas as pd +import streamlit as st + +st.set_page_config("Profiles", "👤") + +@st.cache_data +def get_profile_dataset(number_of_items: int = 100, seed: int = 0) -> pd.DataFrame: + new_data = [] + + def calculate_age(born): + today = date.today() + return ( + today.year - born.year - ((today.month, today.day) < (born.month, born.day)) + ) + + from faker import Faker + + fake = Faker() + random.seed(seed) + Faker.seed(seed) + + for i in range(number_of_items): + profile = fake.profile() + new_data.append( + { + "avatar": f"https://picsum.photos/400/200?lock={i}", + "name": profile["name"], + "age": calculate_age(profile["birthdate"]), + "active": random.choice([True, False]), + "daily_activity": np.random.rand(25), + "homepage": profile["website"][0], + "email": profile["mail"], + "activity": np.random.randint(2, 90, size=25), + "gender": random.choice(["male", "female", "other", None]), + "birthdate": profile["birthdate"], + "status": round(random.uniform(0, 1), 2), + } + ) + + profile_df = pd.DataFrame(new_data) + profile_df["gender"] = profile_df["gender"].astype("category") + return profile_df + + +column_configuration = { + "name": st.column_config.TextColumn( + "Name", help="The name of the user", max_chars=100 + ), + "avatar": st.column_config.ImageColumn("Avatar", help="The user's avatar"), + "active": st.column_config.CheckboxColumn("Is Active?", help="Is the user active?"), + "homepage": st.column_config.LinkColumn( + "Homepage", help="The homepage of the user" + ), + "gender": st.column_config.SelectboxColumn( + "Gender", options=["male", "female", "other"] + ), + "age": st.column_config.NumberColumn( + "Age", + min_value=0, + max_value=120, + format="%d years", + help="The user's age", + ), + "activity": st.column_config.LineChartColumn( + "Activity (1 year)", + help="The user's activity over the last 1 year", + width="large", + y_min=0, + y_max=100, + ), + "daily_activity": st.column_config.BarChartColumn( + "Activity (daily)", + help="The user's activity in the last 25 days", + width="medium", + y_min=0, + y_max=1, + ), + "status": st.column_config.ProgressColumn( + "Status", min_value=0, max_value=1, format="%.2f" + ), + "birthdate": st.column_config.DateColumn( + "Birthdate", + help="The user's birthdate", + min_value=date(1920, 1, 1), + ), + "email": st.column_config.TextColumn( + "Email", + help="The user's email address", + validate="^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$", + ), +} + +st.data_editor( + get_profile_dataset(), + column_config=column_configuration, + use_container_width=True, + hide_index=True, + num_rows="fixed", +) diff --git a/pages/data.data_editor.py b/pages/data.data_editor.py new file mode 100644 index 0000000000000000000000000000000000000000..f8ae0f0a3df1669747f3f618af52531906b7e6f5 --- /dev/null +++ b/pages/data.data_editor.py @@ -0,0 +1,20 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + [ + {"command": "st.selectbox", "rating": 4, "is_widget": True}, + {"command": "st.balloons", "rating": 5, "is_widget": False}, + {"command": "st.time_input", "rating": 3, "is_widget": True}, + ] + ) + + +df = load_data() +edited_df = st.data_editor(df, use_container_width=True) + +favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"] +st.markdown(f"Your favorite command is **{favorite_command}** 🎈") diff --git a/pages/data.data_editor1.py b/pages/data.data_editor1.py new file mode 100644 index 0000000000000000000000000000000000000000..44efa2f45e009bc26d8d9ef7745e82f24f629585 --- /dev/null +++ b/pages/data.data_editor1.py @@ -0,0 +1,20 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + [ + {"command": "st.selectbox", "rating": 4, "is_widget": True}, + {"command": "st.balloons", "rating": 5, "is_widget": False}, + {"command": "st.time_input", "rating": 3, "is_widget": True}, + ] + ) + + +df = load_data() +edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True) + +favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"] +st.markdown(f"Your favorite command is **{favorite_command}** 🎈") diff --git a/pages/data.data_editor2.py b/pages/data.data_editor2.py new file mode 100644 index 0000000000000000000000000000000000000000..a5117dbc2270889dad66fae0071882443828da4e --- /dev/null +++ b/pages/data.data_editor2.py @@ -0,0 +1,17 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + [ + {"command": "st.selectbox", "rating": 4, "is_widget": True}, + {"command": "st.balloons", "rating": 5, "is_widget": False}, + {"command": "st.time_input", "rating": 3, "is_widget": True}, + ] + ) + + +df = load_data() +st.dataframe(df, use_container_width=True) diff --git a/pages/data.data_editor3.py b/pages/data.data_editor3.py new file mode 100644 index 0000000000000000000000000000000000000000..522423ecc08d1b3eb2d31b4bbfbcbb28a1073c80 --- /dev/null +++ b/pages/data.data_editor3.py @@ -0,0 +1,32 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "name": [ + "Kelly Kelley", + "Nicole Nguyen MD", + "Ethan Turner", + "Todd Burton", + "Justin Garcia", + ], + "age": [75, 9, 39, 28, 89], + "gender": ["female", "other", "male", "female", "other"], + "is_active": [True, True, False, True, False], + "status": [0.71, 0.47, 0.6, 0.26, 0.9], + "homepage": [ + "http://edwards.com/", + "https://www.cole.net/", + "https://www.baird-garner.info/", + "https://www.porter.biz/", + "http://ward-romero.org/", + ], + } + ) + + +df = load_data() +edited_df = st.data_editor(df, use_container_width=True, num_rows="dynamic") diff --git a/pages/data.data_editor4.py b/pages/data.data_editor4.py new file mode 100644 index 0000000000000000000000000000000000000000..f523518efb7d477ddfbef215f98b238a0be815c5 --- /dev/null +++ b/pages/data.data_editor4.py @@ -0,0 +1,25 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + data = { + "Animal": ["Lion", "Crocodile", "Elephant", "Giraffe", "Penguin"], + "Weight (kg)": [190, 430, 5000, 800, 4], + "Is Endangered": [True, True, True, False, False], + "Classification": ["Mammal", "Reptile", "Mammal", "Mammal", "Bird"], + "Average Lifespan (years)": [12, 70, 70, 25, 20], + "Habitat": ["Grassland", "Water", "Savannah", "Savannah", "Antarctica"], + } + df = pd.DataFrame(data) + df["Classification"] = df["Classification"].astype("category") + df["Habitat"] = df["Habitat"].astype("category") + return df + + +df = load_data() + +st.data_editor(df, key="data_editor", num_rows="dynamic") +st.write("Here's the session state:") +st.write(st.session_state["data_editor"]) diff --git a/pages/data.data_editor_config.py b/pages/data.data_editor_config.py new file mode 100644 index 0000000000000000000000000000000000000000..da9f17682e7d21a9cd01dbdb03911293a6ed1c3b --- /dev/null +++ b/pages/data.data_editor_config.py @@ -0,0 +1,37 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + [ + {"command": "st.selectbox", "rating": 4, "is_widget": True}, + {"command": "st.balloons", "rating": 5, "is_widget": False}, + {"command": "st.time_input", "rating": 3, "is_widget": True}, + ] + ) + + +df = load_data() + +edited_df = st.data_editor( + df, + column_config={ + "command": "Streamlit Command", + "rating": st.column_config.NumberColumn( + "Your rating", + help="How much do you like this command (1-5)?", + min_value=1, + max_value=5, + step=1, + format="%d ⭐", + ), + "is_widget": "Widget ?", + }, + disabled=["command", "is_widget"], + hide_index=True, +) + +favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"] +st.markdown(f"Your favorite command is **{favorite_command}** 🎈") diff --git a/pages/data.dataframe.py b/pages/data.dataframe.py index ffaeb1ffd30d57d7cbd2b7d38c302966dd452975..97b5fe1293ca80cde2776020b60ecfe04719382b 100644 --- a/pages/data.dataframe.py +++ b/pages/data.dataframe.py @@ -1,12 +1,16 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): - df = pd.DataFrame(np.random.randn(50, 20), columns=("col %d" % i for i in range(20))) + df = pd.DataFrame( + np.random.randn(50, 20), columns=("col %d" % i for i in range(20)) + ) return df + df = load_data() st.dataframe(df) # Same as st.write(df) diff --git a/pages/data.dataframe1.py b/pages/data.dataframe1.py index 1f9cda497fabeff883bb2cd2cc7ebb0b2b90854f..e5a1324cbd20d4bc2f759924f6e5e208da870e2f 100644 --- a/pages/data.dataframe1.py +++ b/pages/data.dataframe1.py @@ -1,12 +1,16 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): - df = pd.DataFrame(np.random.randn(10, 20), columns=("col %d" % i for i in range(20))) + df = pd.DataFrame( + np.random.randn(10, 20), columns=("col %d" % i for i in range(20)) + ) return df + df = load_data() -st.dataframe(df.style.highlight_max(axis=0)) +st.dataframe(df.style.highlight_max(axis=0)) diff --git a/pages/data.dataframe2.py b/pages/data.dataframe2.py index 162142abbafd0d5420a2d3f64073a5b75b8c13bc..1dd2bfe4d7a6275816b2cc21788a93622e1bd278 100644 --- a/pages/data.dataframe2.py +++ b/pages/data.dataframe2.py @@ -3,7 +3,7 @@ import streamlit as st # Cache the dataframe so it's only loaded once -@st.experimental_memo +@st.cache_data def load_data(): return pd.DataFrame( { diff --git a/pages/data.dataframe_config.py b/pages/data.dataframe_config.py new file mode 100644 index 0000000000000000000000000000000000000000..25d708e0965bc4bbaf1778e341b76db95ac06d45 --- /dev/null +++ b/pages/data.dataframe_config.py @@ -0,0 +1,42 @@ +import random + +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "name": ["Roadmap", "Extras", "Issues"], + "url": [ + "https://roadmap.streamlit.app", + "https://extras.streamlit.app", + "https://issues.streamlit.app", + ], + "stars": [random.randint(0, 1000) for _ in range(3)], + "views_history": [ + [random.randint(0, 5000) for _ in range(30)] for _ in range(3) + ], + } + ) + + +df = load_data() + +st.dataframe( + df, + column_config={ + "name": "App name", + "stars": st.column_config.NumberColumn( + "Github Stars", + help="Number of stars on GitHub", + format="%d ⭐", + ), + "url": st.column_config.LinkColumn("App URL"), + "views_history": st.column_config.LineChartColumn( + "Views (past 30 days)", y_min=0, y_max=5000 + ), + }, + hide_index=True, +) diff --git a/pages/data.date_column.py b/pages/data.date_column.py new file mode 100644 index 0000000000000000000000000000000000000000..bbb5fe4b3bfe3e43051ff7584ffd0ba02738c809 --- /dev/null +++ b/pages/data.date_column.py @@ -0,0 +1,35 @@ +from datetime import date + +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "birthday": [ + date(1980, 1, 1), + date(1990, 5, 3), + date(1974, 5, 19), + date(2001, 8, 17), + ] + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "birthday": st.column_config.DateColumn( + "Birthday", + min_value=date(1900, 1, 1), + max_value=date(2005, 1, 1), + format="DD.MM.YYYY", + step=1, + ), + }, + hide_index=True, +) diff --git a/pages/data.datetime_column.py b/pages/data.datetime_column.py new file mode 100644 index 0000000000000000000000000000000000000000..ca20038f8bb4f532ca8315f8c46b5836baa118f8 --- /dev/null +++ b/pages/data.datetime_column.py @@ -0,0 +1,35 @@ +from datetime import datetime + +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "appointment": [ + datetime(2024, 2, 5, 12, 30), + datetime(2023, 11, 10, 18, 0), + datetime(2024, 3, 11, 20, 10), + datetime(2023, 9, 12, 3, 0), + ] + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "appointment": st.column_config.DatetimeColumn( + "Appointment", + min_value=datetime(2023, 6, 1), + max_value=datetime(2025, 1, 1), + format="D MMM YYYY, h:mm a", + step=60, + ), + }, + hide_index=True, +) diff --git a/pages/data.image_column.py b/pages/data.image_column.py new file mode 100644 index 0000000000000000000000000000000000000000..b83115c58c99c02704ba327e136e8e6b33d1ebdb --- /dev/null +++ b/pages/data.image_column.py @@ -0,0 +1,29 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "apps": [ + "https://storage.googleapis.com/s4a-prod-share-preview/default/st_app_screenshot_image/5435b8cb-6c6c-490b-9608-799b543655d3/Home_Page.png", + "https://storage.googleapis.com/s4a-prod-share-preview/default/st_app_screenshot_image/ef9a7627-13f2-47e5-8f65-3f69bb38a5c2/Home_Page.png", + "https://storage.googleapis.com/s4a-prod-share-preview/default/st_app_screenshot_image/31b99099-8eae-4ff8-aa89-042895ed3843/Home_Page.png", + "https://storage.googleapis.com/s4a-prod-share-preview/default/st_app_screenshot_image/6a399b09-241e-4ae7-a31f-7640dc1d181e/Home_Page.png", + ], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "apps": st.column_config.ImageColumn( + "Preview Image", help="Streamlit app preview screenshots" + ) + }, + hide_index=True, +) diff --git a/pages/data.linechart_column.py b/pages/data.linechart_column.py new file mode 100644 index 0000000000000000000000000000000000000000..9b64e26638e7a79d61d87381d1ca89bf5b1d4877 --- /dev/null +++ b/pages/data.linechart_column.py @@ -0,0 +1,33 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "sales": [ + [0, 4, 26, 80, 100, 40], + [80, 20, 80, 35, 40, 100], + [10, 20, 80, 80, 70, 0], + [10, 100, 20, 100, 30, 100], + ], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "sales": st.column_config.LineChartColumn( + "Sales (last 6 months)", + width="medium", + help="The sales volume in the last 6 months", + y_min=0, + y_max=100, + ), + }, + hide_index=True, +) diff --git a/pages/data.link_column.py b/pages/data.link_column.py new file mode 100644 index 0000000000000000000000000000000000000000..8276e29faebbd3d49513bd5db8a0208da630c57a --- /dev/null +++ b/pages/data.link_column.py @@ -0,0 +1,32 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "apps": [ + "https://roadmap.streamlit.app", + "https://extras.streamlit.app", + "https://issues.streamlit.app", + "https://30days.streamlit.app", + ], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "apps": st.column_config.LinkColumn( + "Trending apps", + help="The top trending Streamlit apps", + validate="^https://[a-z]+\.streamlit\.app$", + max_chars=100, + ) + }, + hide_index=True, +) diff --git a/pages/data.list_column.py b/pages/data.list_column.py new file mode 100644 index 0000000000000000000000000000000000000000..97e0800af55e5949f3501bd25fa80f6723c4da4f --- /dev/null +++ b/pages/data.list_column.py @@ -0,0 +1,31 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "sales": [ + [0, 4, 26, 80, 100, 40], + [80, 20, 80, 35, 40, 100], + [10, 20, 80, 80, 70, 0], + [10, 100, 20, 100, 30, 100], + ], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "sales": st.column_config.ListColumn( + "Sales (last 6 months)", + help="The sales volume in the last 6 months", + width="medium", + ), + }, + hide_index=True, +) diff --git a/pages/data.number_column.py b/pages/data.number_column.py new file mode 100644 index 0000000000000000000000000000000000000000..fef44dbff02bba7cd891083ab2bddab8f44b2f1c --- /dev/null +++ b/pages/data.number_column.py @@ -0,0 +1,29 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "price": [20, 950, 250, 500], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "price": st.column_config.NumberColumn( + "Price (in USD)", + help="The price of the product in USD", + min_value=0, + max_value=1000, + step=1, + format="$%d", + ) + }, + hide_index=True, +) diff --git a/pages/data.progress_column.py b/pages/data.progress_column.py new file mode 100644 index 0000000000000000000000000000000000000000..1c3831937cf2c92eedc5a0a7aa3971f8c45d8ac7 --- /dev/null +++ b/pages/data.progress_column.py @@ -0,0 +1,28 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "sales": [200, 550, 1000, 80], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "sales": st.column_config.ProgressColumn( + "Sales volume", + help="The sales volume in USD", + format="$%f", + min_value=0, + max_value=1000, + ), + }, + hide_index=True, +) diff --git a/pages/data.selectbox_column.py b/pages/data.selectbox_column.py new file mode 100644 index 0000000000000000000000000000000000000000..0fda5def9ee635adffdad9c0290fa326f646d0c7 --- /dev/null +++ b/pages/data.selectbox_column.py @@ -0,0 +1,37 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "category": [ + "📊 Data Exploration", + "📈 Data Visualization", + "🤖 LLM", + "📊 Data Exploration", + ], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "category": st.column_config.SelectboxColumn( + "App Category", + help="The category of the app", + width="medium", + options=[ + "📊 Data Exploration", + "📈 Data Visualization", + "🤖 LLM", + ], + required=True, + ) + }, + hide_index=True, +) diff --git a/pages/data.table.py b/pages/data.table.py index e1c0b882a5ef2fe595f51f28af6605a3dd7d51fc..129bbefe681b90e8eed4b0e47bb81f7035290728 100644 --- a/pages/data.table.py +++ b/pages/data.table.py @@ -1,12 +1,14 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st + -@st.experimental_memo +@st.cache_data def load_data(): df = pd.DataFrame(np.random.randn(10, 5), columns=("col %d" % i for i in range(5))) return df + df = load_data() st.table(df) diff --git a/pages/data.text_column.py b/pages/data.text_column.py new file mode 100644 index 0000000000000000000000000000000000000000..04e5892add49432b49fd7a04f43ccd37f5fb1913 --- /dev/null +++ b/pages/data.text_column.py @@ -0,0 +1,28 @@ +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "widgets": ["st.selectbox", "st.number_input", "st.text_area", "st.button"], + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "widgets": st.column_config.TextColumn( + "Widgets", + help="Streamlit **widget** commands 🎈", + default="st.", + max_chars=50, + validate="^st\.[a-z_]+$", + ) + }, + hide_index=True, +) diff --git a/pages/data.time_column.py b/pages/data.time_column.py new file mode 100644 index 0000000000000000000000000000000000000000..f2fe590d816dec68db25e9b411cd05e50600df7a --- /dev/null +++ b/pages/data.time_column.py @@ -0,0 +1,35 @@ +from datetime import time + +import pandas as pd +import streamlit as st + + +@st.cache_data +def load_data(): + return pd.DataFrame( + { + "appointment": [ + time(12, 30), + time(18, 0), + time(9, 10), + time(16, 25), + ] + } + ) + + +data_df = load_data() + +st.data_editor( + data_df, + column_config={ + "appointment": st.column_config.TimeColumn( + "Appointment", + min_value=time(8, 0, 0), + max_value=time(19, 0, 0), + format="hh:mm a", + step=60, + ), + }, + hide_index=True, +) diff --git a/pages/forms.form_container.py b/pages/forms.form_container.py new file mode 100644 index 0000000000000000000000000000000000000000..2a672398ceb619b384cd6e50d8d96ce7c9f4ef96 --- /dev/null +++ b/pages/forms.form_container.py @@ -0,0 +1,16 @@ +import streamlit as st + +animal = st.form('my_animal') + +# This is writing directly to the main body. Since the form container is +# defined above, this will appear below everything written in the form. +sound = st.selectbox('Sounds like', ['meow','woof','squeak','tweet']) + +# These methods called on the form container, so they appear inside the form. +submit = animal.form_submit_button(f'Say it with {sound}!') +sentence = animal.text_input('Your sentence:', 'Where\'s the tuna?') +say_it = sentence.rstrip('.,!?') + f', {sound}!' +if submit: + animal.subheader(say_it) +else: + animal.subheader(' ') diff --git a/pages/forms.form_default.py b/pages/forms.form_default.py new file mode 100644 index 0000000000000000000000000000000000000000..1852126dfb424de79703b44adef971f60edc390e --- /dev/null +++ b/pages/forms.form_default.py @@ -0,0 +1,11 @@ +import streamlit as st + +with st.form("my_form"): + st.write("Inside the form") + my_number = st.slider('Pick a number', 1, 10) + my_color = st.selectbox('Pick a color', ['red','orange','green','blue','violet']) + st.form_submit_button('Submit my picks') + +# This is outside the form +st.write(my_number) +st.write(my_color) diff --git a/pages/forms.form_overview.py b/pages/forms.form_overview.py new file mode 100644 index 0000000000000000000000000000000000000000..db5dac3d4ff8bd2aedc6f59d32c8caea17d426bc --- /dev/null +++ b/pages/forms.form_overview.py @@ -0,0 +1,43 @@ +import streamlit as st +import pandas as pd +import numpy as np + +def get_data(): + df = pd.DataFrame({ + "lat": np.random.randn(200) / 50 + 37.76, + "lon": np.random.randn(200) / 50 + -122.4, + "team": ['A','B']*100 + }) + return df + +if st.button('Generate new points'): + st.session_state.df = get_data() +if 'df' not in st.session_state: + st.session_state.df = get_data() +df = st.session_state.df + +with st.form("my_form"): + header = st.columns([1,2,2]) + header[0].subheader('Color') + header[1].subheader('Opacity') + header[2].subheader('Size') + + row1 = st.columns([1,2,2]) + colorA = row1[0].color_picker('Team A', '#0000FF') + opacityA = row1[1].slider('A opacity', 20, 100, 50, label_visibility='hidden') + sizeA = row1[2].slider('A size', 50, 200, 100, step=10, label_visibility='hidden') + + row2 = st.columns([1,2,2]) + colorB = row2[0].color_picker('Team B', '#FF0000') + opacityB = row2[1].slider('B opacity', 20, 100, 50, label_visibility='hidden') + sizeB = row2[2].slider('B size', 50, 200, 100, step=10, label_visibility='hidden') + + st.form_submit_button('Update map') + +alphaA = int(opacityA*255/100) +alphaB = int(opacityB*255/100) + +df['color'] = np.where(df.team=='A',colorA+f'{alphaA:02x}',colorB+f'{alphaB:02x}') +df['size'] = np.where(df.team=='A',sizeA, sizeB) + +st.map(df, size='size', color='color') diff --git a/pages/forms.form_process1.py b/pages/forms.form_process1.py new file mode 100644 index 0000000000000000000000000000000000000000..fe61f6bac4997d9a40bd2238674277b24172a005 --- /dev/null +++ b/pages/forms.form_process1.py @@ -0,0 +1,12 @@ +import streamlit as st + +col1,col2 = st.columns([1,2]) +col1.title('Sum:') + +with st.form('addition'): + a = st.number_input('a') + b = st.number_input('b') + submit = st.form_submit_button('add') + +if submit: + col2.title(f'{a+b:.2f}') diff --git a/pages/forms.form_process2.py b/pages/forms.form_process2.py new file mode 100644 index 0000000000000000000000000000000000000000..4a355499665b253fc36f0057c1730ddc1f23b102 --- /dev/null +++ b/pages/forms.form_process2.py @@ -0,0 +1,18 @@ +import streamlit as st + +if 'sum' not in st.session_state: + st.session_state.sum = '' + +def sum(): + result = st.session_state.a + st.session_state.b + st.session_state.sum = result + +col1,col2 = st.columns(2) +col1.title('Sum:') +if isinstance(st.session_state.sum, float): + col2.title(f'{st.session_state.sum:.2f}') + +with st.form('addition'): + st.number_input('a', key = 'a') + st.number_input('b', key = 'b') + st.form_submit_button('add', on_click=sum) diff --git a/pages/forms.form_process3.py b/pages/forms.form_process3.py new file mode 100644 index 0000000000000000000000000000000000000000..4cea83f3cfa7f353586bdabc3717aed152582aeb --- /dev/null +++ b/pages/forms.form_process3.py @@ -0,0 +1,21 @@ +import streamlit as st + +if 'sum' not in st.session_state: + st.session_state.sum = '' + +col1,col2 = st.columns(2) +col1.title('Sum:') +if isinstance(st.session_state.sum, float): + col2.title(f'{st.session_state.sum:.2f}') + +with st.form('addition'): + a = st.number_input('a') + b = st.number_input('b') + submit = st.form_submit_button('add') + +# The value of st.session_state.sum is updated at the end of the script rerun, +# so the displayed value at the top in col2 does not show the new sum. Trigger +# a second rerun when the form is submitted to update the value above. +st.session_state.sum = a + b +if submit: + st.experimental_rerun() diff --git a/pages/layout.columns2.py b/pages/layout.columns2.py index 189832d72d22e477cbc4bc3f284b4b7b2d5eee30..e0eebca077cb9b7161f400e14cc9ef5597ca7494 100644 --- a/pages/layout.columns2.py +++ b/pages/layout.columns2.py @@ -1,11 +1,13 @@ -import streamlit as st import numpy as np +import streamlit as st -@st.experimental_memo + +@st.cache_data def load_data(): data = np.random.randn(10, 1) return data + col1, col2 = st.columns([3, 1]) data = load_data() diff --git a/pages/requirements.txt b/pages/requirements.txt index 8659f85b20c22f0bcbf632f1d7b8dec08b98dff8..b8e1121bc77c09e949fc130082666733ae0a818c 100644 --- a/pages/requirements.txt +++ b/pages/requirements.txt @@ -1,11 +1,13 @@ -pandas==1.2.5 -plotly==5.1.0 +pandas==1.5.3 +plotly==5.13.0 bokeh==2.4.3 -graphviz==0.17 -requests==2.22.0 -matplotlib==3.4.1 -numpy==1.22.0 +graphviz==0.20 +requests==2.31.0 +matplotlib==3.7.1 +numpy==1.23.5 scipy altair==4.2.0 -pydeck==0.7.1 -streamlit==1.13.0 \ No newline at end of file +pydeck==0.8.0 +Faker==19.1.0 +openai==0.27.8 +streamlit==1.26.0 diff --git a/pages/status.status.py b/pages/status.status.py new file mode 100644 index 0000000000000000000000000000000000000000..a83c422a11005009d5c18672e57f0c8ef0e96665 --- /dev/null +++ b/pages/status.status.py @@ -0,0 +1,12 @@ +import time +import streamlit as st + +with st.status("Downloading data..."): + st.write("Searching for data...") + time.sleep(2) + st.write("Found URL.") + time.sleep(1) + st.write("Downloading data...") + time.sleep(1) + +st.button('Rerun') diff --git a/pages/status.status1.py b/pages/status.status1.py new file mode 100644 index 0000000000000000000000000000000000000000..ff7164089a1c7a1dc9a2f132c345c9b1535decac --- /dev/null +++ b/pages/status.status1.py @@ -0,0 +1,13 @@ +import time +import streamlit as st + +with st.status("Downloading data...", expanded=True) as status: + st.write("Searching for data...") + time.sleep(2) + st.write("Found URL.") + time.sleep(1) + st.write("Downloading data...") + time.sleep(1) + status.update(label="Download complete!", state="complete", expanded=False) + +st.button('Rerun') diff --git a/pages/status.toast1.py b/pages/status.toast1.py new file mode 100644 index 0000000000000000000000000000000000000000..eaa2db84433ab8d72ef38eef61c9b2ecd4fad724 --- /dev/null +++ b/pages/status.toast1.py @@ -0,0 +1,9 @@ +import streamlit as st +import time + +if st.button('Three cheers'): + st.toast('Hip!') + time.sleep(.5) + st.toast('Hip!') + time.sleep(.5) + st.toast('Hooray!', icon='🎉') diff --git a/pages/status.toast2.py b/pages/status.toast2.py new file mode 100644 index 0000000000000000000000000000000000000000..98da6b5cda7c52f973306724b3c44427969b461e --- /dev/null +++ b/pages/status.toast2.py @@ -0,0 +1,12 @@ +import streamlit as st +import time + +def cook_breakfast(): + msg = st.toast('Gathering ingredients...') + time.sleep(1) + msg.toast('Cooking...') + time.sleep(1) + msg.toast('Ready!', icon = "đŸĨž") + +if st.button('Cook breakfast'): + cook_breakfast() diff --git a/pages/text.header.py b/pages/text.header.py index ad87d1884fca4b69d4f0c5fdb2a6f0dd5e364e29..9b65a92fd18968819ba37be6e05eb1704d03598b 100644 --- a/pages/text.header.py +++ b/pages/text.header.py @@ -1,3 +1,4 @@ import streamlit as st -st.header("This is a header") +st.header('This is a header with a divider', divider='rainbow') +st.header('_Streamlit_ is :blue[cool] :sunglasses:') diff --git a/pages/text.markdown.py b/pages/text.markdown.py index b883b0bbabc3ff43a9157951cd72d2d102d556a8..1c8dfd45e347b61f6a818e2f53f4fd1e0367c5be 100644 --- a/pages/text.markdown.py +++ b/pages/text.markdown.py @@ -1,3 +1,15 @@ import streamlit as st -st.markdown("Streamlit is **_really_ cool**.") +st.markdown("*Streamlit* is **really** ***cool***.") +st.markdown(""" + :red[Streamlit] :orange[can] :green[write] :blue[text] :violet[in] + :gray[pretty] :rainbow[colors].""") +st.markdown("Here's a bouquet —\ + :tulip::cherry_blossom::rose::hibiscus::sunflower::blossom:") + +multi = '''If you end a line with two spaces, +a soft return is used for the next line. + +Two (or more) newline characters in a row will result in a hard return. +''' +st.markdown(multi) diff --git a/pages/text.markdown1.py b/pages/text.markdown1.py new file mode 100644 index 0000000000000000000000000000000000000000..cce5a43fa96c82e7f6948959aab58469c4659334 --- /dev/null +++ b/pages/text.markdown1.py @@ -0,0 +1,12 @@ +import streamlit as st + +md = st.text_area('Type in your markdown string (without outer quotes)', + "Happy Streamlit-ing! :balloon:") + +st.code(f""" +import streamlit as st + +st.markdown('''{md}''') +""") + +st.markdown(md) diff --git a/pages/text.subheader.py b/pages/text.subheader.py index 1bec0b1c222cc447a236c65554eddb386591fac1..8c86dc882ff5a99f50debb72e192061da249995e 100644 --- a/pages/text.subheader.py +++ b/pages/text.subheader.py @@ -1,3 +1,4 @@ import streamlit as st -st.subheader("This is a subheader") +st.subheader('This is a subheader with a divider', divider='rainbow') +st.subheader('_Streamlit_ is :blue[cool] :sunglasses:') diff --git a/pages/text.title.py b/pages/text.title.py index 38586b146963b422adf36b31e2a91350608ef51c..73772765fd8703eafdca2fd04b9e1d8d5afe54b9 100644 --- a/pages/text.title.py +++ b/pages/text.title.py @@ -1,3 +1,4 @@ import streamlit as st -st.title("This is a title") +st.title('This is a title') +st.title('_Streamlit_ is :blue[cool] :sunglasses:') diff --git a/pages/text.write3.py b/pages/text.write3.py index 1e8de7bc6441558f6a87caf2f277028e9002e4c4..7f3e4541fc7b60ab0448d4743cf4512dc914b154 100644 --- a/pages/text.write3.py +++ b/pages/text.write3.py @@ -1,13 +1,15 @@ -import streamlit as st import pandas as pd +import streamlit as st -@st.experimental_memo + +@st.cache_data def load_data(): data_frame = pd.DataFrame( {"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]} ) return data_frame + data_frame = load_data() st.write("1 + 1 = ", 2) st.write("Below is a DataFrame:", data_frame, "Above is a dataframe.") diff --git a/pages/utilities.help.py b/pages/utilities.help.py new file mode 100644 index 0000000000000000000000000000000000000000..9eeb4af2506bb7e2599aab5ef2b837773025206f --- /dev/null +++ b/pages/utilities.help.py @@ -0,0 +1,4 @@ +import pandas +import streamlit as st + +st.help(pandas.DataFrame) diff --git a/pages/utilities.help1.py b/pages/utilities.help1.py new file mode 100644 index 0000000000000000000000000000000000000000..3f4c068d7f5956024505335c684a938e4a622117 --- /dev/null +++ b/pages/utilities.help1.py @@ -0,0 +1,17 @@ +import streamlit as st + + +class Dog: + """A typical dog.""" + + def __init__(self, breed, color): + self.breed = breed + self.color = color + + def bark(self): + return "Woof!" + + +fido = Dog("poodle", "white") + +st.help(fido) diff --git a/pages/utilities.help2.py b/pages/utilities.help2.py new file mode 100644 index 0000000000000000000000000000000000000000..8b6bbd3deca999def0ce2fc88a5b776c6c749653 --- /dev/null +++ b/pages/utilities.help2.py @@ -0,0 +1,8 @@ +import pandas +import streamlit as st + +# Get help for Pandas read_csv: +pandas.read_csv + +# Get help for Streamlit itself: +st diff --git a/pages/widget.button.py b/pages/widget.button.py index 07d1996441be43e8458cf3f300ca5d86e63f5886..85540b67ddae434b06af3ffb57001e2401441a00 100644 --- a/pages/widget.button.py +++ b/pages/widget.button.py @@ -1,6 +1,7 @@ import streamlit as st -if st.button("Say hello"): - st.write("Why hello there") +st.button('Reset', type='primary') +if st.button('Say hello'): + st.write('Why hello there') else: - st.write("Goodbye") + st.write('Goodbye') diff --git a/pages/widget.date_input1.py b/pages/widget.date_input1.py new file mode 100644 index 0000000000000000000000000000000000000000..04ab2a42fc4d306c567b43c7fe31e5e784dc4b52 --- /dev/null +++ b/pages/widget.date_input1.py @@ -0,0 +1,18 @@ +import datetime + +import streamlit as st + +today = datetime.datetime.now() +next_year = today.year + 1 +jan_1 = datetime.date(next_year, 1, 1) +dec_31 = datetime.date(next_year, 12, 31) + +d = st.date_input( + "Select your vacation for next year", + (jan_1, datetime.date(next_year, 1, 7)), + jan_1, + dec_31, + format="MM.DD.YYYY", +) + +d diff --git a/pages/widget.download_button.py b/pages/widget.download_button.py index 76e90180793918234928ac0cb80c36e4ff4b9377..1b30343f777901f65d2f9b8e7e83a805f8592aa8 100644 --- a/pages/widget.download_button.py +++ b/pages/widget.download_button.py @@ -1,41 +1,39 @@ -import streamlit as st -import pandas as pd import numpy as np +import pandas as pd +import streamlit as st -@st.experimental_memo + +@st.cache_data def load_data(): - data = pd.DataFrame( - np.random.randn(1000, 2), - columns=['a', 'b']) + data = pd.DataFrame(np.random.randn(1000, 2), columns=["a", "b"]) return data -@st.experimental_memo + +@st.cache_data def convert_df(df): # IMPORTANT: Cache the conversion to prevent computation on every rerun - return df.to_csv().encode('utf-8') + return df.to_csv().encode("utf-8") + my_large_df = load_data() csv = convert_df(my_large_df) st.download_button( - label="Download data as CSV", - data=csv, - file_name='large_df.csv', - mime='text/csv', - ) + label="Download data as CSV", + data=csv, + file_name="large_df.csv", + mime="text/csv", +) -text_contents = '''This is some text''' -st.download_button('Download some text', text_contents) +text_contents = """This is some text""" +st.download_button("Download some text", text_contents) -binary_contents = b'example content' +binary_contents = b"example content" # Defaults to 'application/octet-stream' -st.download_button('Download binary file', binary_contents) +st.download_button("Download binary file", binary_contents) -with open("pages/flower.png", "rb") as file: +with open("python/api-examples-source/flower.png", "rb") as file: btn = st.download_button( - label="Download image", - data=file, - file_name="flower.png", - mime="image/png" + label="Download image", data=file, file_name="flower.png", mime="image/png" ) diff --git a/pages/widget.radio.py b/pages/widget.radio.py index 24ac59c854274fd8a170b5b247fcaf9b8fcc24a7..11d9405daf47eba2f3dc9736161c98ad324058be 100644 --- a/pages/widget.radio.py +++ b/pages/widget.radio.py @@ -1,8 +1,11 @@ import streamlit as st -genre = st.radio("What's your favorite movie genre", ("Comedy", "Drama", "Documentary")) +genre = st.radio( + "What's your favorite movie genre", + [":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"], + captions = ["Laugh out loud.", "Get the popcorn.", "Never stop learning."]) -if genre == "Comedy": +if genre == ":rainbow[Comedy]": st.write("You selected comedy.") else: st.write("You didn't select comedy.") diff --git a/pages/widget.toggle.py b/pages/widget.toggle.py new file mode 100644 index 0000000000000000000000000000000000000000..7ee2a4e4524ec00c11029ab507c993133843fa86 --- /dev/null +++ b/pages/widget.toggle.py @@ -0,0 +1,6 @@ +import streamlit as st + +on = st.toggle('Activate feature') + +if on: + st.write('Feature activated!')