Skip to content

Commit 4187617

Browse files
Prerelease 1.48.0: Apps (#1317)
* Use numpy Generator instance in app examples * Apps for 1.48.0 features * Bump streamlit version
1 parent 2d99de5 commit 4187617

File tree

65 files changed

+237
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+237
-403
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.black]
2+
line-length = 79

python/api-examples-source/charts.altair_selections.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import streamlit as st
2-
import pandas as pd
3-
import numpy as np
41
import altair as alt
2+
import pandas as pd
3+
import streamlit as st
4+
from numpy.random import default_rng as rng
55

6-
7-
@st.cache_data
8-
def load_data():
9-
return pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
10-
11-
12-
df = load_data()
6+
df = pd.DataFrame(rng(0).standard_normal((20, 3)), columns=["a", "b", "c"])
137

148
point_selector = alt.selection_point("point_selection")
159
interval_selector = alt.selection_interval("interval_selection")
@@ -22,7 +16,9 @@ def load_data():
2216
size="c",
2317
color="c",
2418
tooltip=["a", "b", "c"],
25-
fillOpacity=alt.condition(point_selector, alt.value(1), alt.value(0.3)),
19+
fillOpacity=alt.condition(
20+
point_selector, alt.value(1), alt.value(0.3)
21+
),
2622
)
2723
.add_params(point_selector, interval_selector)
2824
)
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import numpy as np
21
import pandas as pd
32
import streamlit as st
3+
from numpy.random import default_rng as rng
44

5+
df = pd.DataFrame(rng(0).standard_normal((20, 3)), columns=["a", "b", "c"])
56

6-
@st.cache_data
7-
def load_data():
8-
df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
9-
return df
10-
11-
12-
chart_data = load_data()
13-
14-
st.area_chart(chart_data)
7+
st.area_chart(df)
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import numpy as np
21
import pandas as pd
32
import streamlit as st
3+
from numpy.random import default_rng as rng
44

5+
df = pd.DataFrame(
6+
{
7+
"col1": list(range(20)) * 3,
8+
"col2": rng(0).standard_normal(60),
9+
"col3": ["a"] * 20 + ["b"] * 20 + ["c"] * 20,
10+
}
11+
)
512

6-
@st.cache_data
7-
def load_data():
8-
df = pd.DataFrame(
9-
{
10-
"col1": np.random.randn(20),
11-
"col2": np.random.randn(20),
12-
"col3": np.random.choice(["A", "B", "C"], 20),
13-
}
14-
)
15-
return df
16-
17-
18-
chart_data = load_data()
19-
20-
st.area_chart(chart_data, x="col1", y="col2", color="col3")
13+
st.area_chart(df, x="col1", y="col2", color="col3")
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import numpy as np
21
import pandas as pd
32
import streamlit as st
3+
from numpy.random import default_rng as rng
44

5-
6-
@st.cache_data
7-
def load_data():
8-
df = pd.DataFrame(np.random.randn(20, 3), columns=["col1", "col2", "col3"])
9-
return df
10-
11-
12-
chart_data = load_data()
5+
df = pd.DataFrame(
6+
{
7+
"col1": list(range(20)),
8+
"col2": rng(0).standard_normal(20),
9+
"col3": rng(1).standard_normal(20),
10+
}
11+
)
1312

1413
st.area_chart(
15-
chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"] # Optional
14+
df,
15+
x="col1",
16+
y=["col2", "col3"],
17+
color=["#FF000080", "#0000FF80"],
1618
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import streamlit as st
22
from vega_datasets import data
33

4-
source = data.unemployment_across_industries()
4+
df = data.unemployment_across_industries()
55

6-
st.area_chart(source, x="date", y="count", color="series", stack="center")
6+
st.area_chart(df, x="date", y="count", color="series", stack="center")
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import numpy as np
21
import pandas as pd
32
import streamlit as st
3+
from numpy.random import default_rng as rng
44

5+
df = pd.DataFrame(rng(0).standard_normal((20, 3)), columns=["a", "b", "c"])
56

6-
@st.cache_data
7-
def load_data():
8-
df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
9-
return df
10-
11-
12-
chart_data = load_data()
13-
14-
st.bar_chart(chart_data)
7+
st.bar_chart(df)
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import numpy as np
21
import pandas as pd
32
import streamlit as st
3+
from numpy.random import default_rng as rng
44

5+
df = pd.DataFrame(
6+
{
7+
"col1": list(range(20)) * 3,
8+
"col2": rng(0).standard_normal(60),
9+
"col3": ["a"] * 20 + ["b"] * 20 + ["c"] * 20,
10+
}
11+
)
512

6-
@st.cache_data
7-
def load_data():
8-
df = pd.DataFrame(
9-
{
10-
"col1": list(range(20)) * 3,
11-
"col2": np.random.randn(60),
12-
"col3": ["A"] * 20 + ["B"] * 20 + ["C"] * 20,
13-
}
14-
)
15-
return df
16-
17-
18-
chart_data = load_data()
19-
20-
st.bar_chart(chart_data, x="col1", y="col2", color="col3")
13+
st.bar_chart(df, x="col1", y="col2", color="col3")
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import numpy as np
21
import pandas as pd
32
import streamlit as st
3+
from numpy.random import default_rng as rng
44

5-
6-
@st.cache_data
7-
def load_data():
8-
df = pd.DataFrame(
9-
{
10-
"col1": list(range(20)),
11-
"col2": np.random.randn(20),
12-
"col3": np.random.randn(20),
13-
}
14-
)
15-
return df
16-
17-
18-
chart_data = load_data()
5+
df = pd.DataFrame(
6+
{
7+
"col1": list(range(20)),
8+
"col2": rng(0).standard_normal(20),
9+
"col3": rng(1).standard_normal(20),
10+
}
11+
)
1912

2013
st.bar_chart(
21-
chart_data, x="col1", y=["col2", "col3"], color=["#FF0000", "#0000FF"] # Optional
14+
df,
15+
x="col1",
16+
y=["col2", "col3"],
17+
color=["#FF0000", "#0000FF"],
2218
)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import streamlit as st
22
from vega_datasets import data
33

4-
@st.cache_data
5-
def get_data():
6-
return data.barley()
7-
8-
source = get_data()
4+
source = data.barley()
95

106
st.bar_chart(source, x="variety", y="yield", color="site", horizontal=True)

0 commit comments

Comments
 (0)