Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions python/api-examples-source/charts.area_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@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


Expand Down
19 changes: 8 additions & 11 deletions python/api-examples-source/charts.area_chart1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@

@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)
})
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'
)
st.area_chart(chart_data, x="col1", y="col2", color="col3")
9 changes: 2 additions & 7 deletions python/api-examples-source/charts.area_chart2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@

@st.cache_data
def load_data():
df = pd.DataFrame(
np.random.randn(20, 3),
columns = ['col1', 'col2', 'col3'])
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
chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"] # Optional
)
4 changes: 1 addition & 3 deletions python/api-examples-source/charts.bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@st.cache_data
def load_data():
df = pd.DataFrame(
np.random.randn(50, 3),
columns = ["a", "b", "c"])
df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
return df


Expand Down
19 changes: 8 additions & 11 deletions python/api-examples-source/charts.bar_chart1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@

@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
})
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'
)
st.bar_chart(chart_data, x="col1", y="col2", color="col3")
17 changes: 8 additions & 9 deletions python/api-examples-source/charts.bar_chart2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@

@st.cache_data
def load_data():
df = pd.DataFrame({
'col1' : list(range(20)),
'col2' : np.random.randn(20),
'col3' : np.random.randn(20)
})
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
chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"] # Optional
)
4 changes: 1 addition & 3 deletions python/api-examples-source/charts.line_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@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


Expand Down
19 changes: 8 additions & 11 deletions python/api-examples-source/charts.line_chart1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@

@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)
})
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'
)
st.line_chart(chart_data, x="col1", y="col2", color="col3")
9 changes: 2 additions & 7 deletions python/api-examples-source/charts.line_chart2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@

@st.cache_data
def load_data():
df = pd.DataFrame(
np.random.randn(20, 3),
columns = ['col1', 'col2', 'col3'])
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
chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"] # Optional
)
14 changes: 14 additions & 0 deletions python/api-examples-source/charts.scatter_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import streamlit as st
import pandas as pd
import numpy as np


@st.cache_data
def load_data():
df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
return df


chart_data = load_data()

st.scatter_chart(chart_data)
21 changes: 21 additions & 0 deletions python/api-examples-source/charts.scatter_chart1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import streamlit as st
import pandas as pd
import numpy as np


@st.cache_data
def load_data():
df = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"])
df["col4"] = np.random.choice(["A", "B", "C"], 20)
return df


chart_data = load_data()

st.scatter_chart(
chart_data,
x="col1",
y="col2",
color="col4",
size="col3",
)
20 changes: 20 additions & 0 deletions python/api-examples-source/charts.scatter_chart2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import streamlit as st
import pandas as pd
import numpy as np


@st.cache_data
def load_data():
df = pd.DataFrame(np.random.randn(20, 4), columns=["col1", "col2", "col3", "col4"])
return df


chart_data = load_data()

st.scatter_chart(
chart_data,
x="col1",
y=["col2", "col3"],
size="col4",
color=["#FF0000", "#0000FF"], # Optional
)
16 changes: 9 additions & 7 deletions python/api-examples-source/data.column_config.empty.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import streamlit as st
import pandas as pd

df = pd.DataFrame(columns=['name','age','color'])
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
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)
"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')
result = st.data_editor(df, column_config=config, num_rows="dynamic")

if st.button('Get results'):
if st.button("Get results"):
st.write(result)
1 change: 1 addition & 0 deletions python/api-examples-source/data.column_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

st.set_page_config("Profiles", "👤")


@st.cache_data
def get_profile_dataset(number_of_items: int = 100, seed: int = 0) -> pd.DataFrame:
new_data = []
Expand Down
12 changes: 6 additions & 6 deletions python/api-examples-source/forms.form_container.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import streamlit as st

animal = st.form('my_animal')
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'])
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}!'
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(' ')
animal.subheader(" ")
10 changes: 6 additions & 4 deletions python/api-examples-source/forms.form_default.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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')
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)
Expand Down
56 changes: 31 additions & 25 deletions python/api-examples-source/forms.form_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@
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
})
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'):

if st.button("Generate new points"):
st.session_state.df = get_data()
if 'df' not in st.session_state:
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')
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')
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')
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')
st.form_submit_button("Update map")

alphaA = int(opacityA*255/100)
alphaB = int(opacityB*255/100)
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)
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')
st.map(df, size="size", color="color")
Loading