Skip to content

Commit

Permalink
Merge branch 'main' into feature/bypass-arrow-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Aug 23, 2023
2 parents 1f37120 + ff9c764 commit ec9d97c
Show file tree
Hide file tree
Showing 162 changed files with 7,743 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ data_in_bytes = await response.bytes()
A tutorial to convert a Streamlit app to an executable file with stlite and a demo to run it on an offline machine.
- [📖 "Is This the Easiest Way to Build Your Streamlit App?", by Shantala Mukherjee](https://onlyweb.hashnode.dev/is-this-the-easiest-way-to-build-your-streamlit-app)
- [📖 "The Best Python Desktop App Framework?", by Caleb Robey at Depot Analytics](https://www.depotanalytics.co/post/the-best-python-desktop-app-framework)
- [📖 "Python-Based Data Viz (With No Installation Required)", by Sam Minot](https://towardsdatascience.com/python-based-data-viz-with-no-installation-required-aaf2358c881)
- [📖 "Converting Streamlit application to exe file", by Neelasha Sen](https://ploomber.io/blog/streamlit_exe/)
- [📖 "Streamlit + Stlite: Beyond Data Science Applications", by Saumitra Panchal](https://medium.com/@saumitrapanchal/streamlit-stlite-beyond-data-science-applications-23de64648883)

## Samples

Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/bin/dump_artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async function createSitePackagesSnapshot(
pyodide,
path.join(
stliteKernelPyDir,
"streamlit/lib/dist/streamlit-1.24.0-py2.py3-none-any.whl"
"streamlit/lib/dist/streamlit-1.24.0-cp311-none-any.whl"
)
);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import altair as alt
import streamlit as st
from vega_datasets import data


@st.cache_data
def get_chart(use_container_width: bool):
import altair as alt
from vega_datasets import data

source = data.cars()

chart = (
alt.Chart(source)
.mark_circle()
.encode(
x="Horsepower",
y="Miles_per_Gallon",
color="Origin",
)
.interactive()
)

tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])

with tab1:
st.altair_chart(
chart, use_container_width=use_container_width, theme="streamlit"
)
with tab2:
st.altair_chart(chart, use_container_width=use_container_width, theme=None)


try:
get_chart(use_container_width=True)
except Exception as e:
st.exception(e)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import altair as alt
import streamlit as st
from vega_datasets import data


@st.cache_data
def get_chart(use_container_width: bool):
import altair as alt
from vega_datasets import data

source = data.seattle_weather()

scale = alt.Scale(
domain=["sun", "fog", "drizzle", "rain", "snow"],
range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
)
color = alt.Color("weather:N", scale=scale)

# We create two selections:
# - a brush that is active on the top panel
# - a multi-click that is active on sthe bottom panel
brush = alt.selection_interval(encodings=["x"])
click = alt.selection_multi(encodings=["color"])

# Top panel is scatter plot of temperature vs time
points = (
alt.Chart()
.mark_point()
.encode(
alt.X("monthdate(date):T", title="Date"),
alt.Y(
"temp_max:Q",
title="Maximum Daily Temperature (C)",
scale=alt.Scale(domain=[-5, 40]),
),
color=alt.condition(brush, color, alt.value("lightgray")),
size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
)
.properties(width=550, height=300)
.add_selection(brush)
.transform_filter(click)
)

# Bottom panel is a bar chart of weather type
bars = (
alt.Chart()
.mark_bar()
.encode(
x="count()",
y="weather:N",
color=alt.condition(click, color, alt.value("lightgray")),
)
.transform_filter(brush)
.properties(
width=550,
)
.add_selection(click)
)

chart = alt.vconcat(points, bars, data=source, title="Seattle Weather: 2012-2015")

tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])

with tab1:
st.altair_chart(
chart, use_container_width=use_container_width, theme="streamlit"
)
with tab2:
st.altair_chart(chart, use_container_width=use_container_width, theme=None)


try:
get_chart(use_container_width=True)
except Exception as e:
st.exception(e)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import plotly.express as px
import streamlit as st


@st.cache_data
def get_chart(use_container_width: bool):
df = px.data.gapminder()

fig = px.scatter(
df.query("year==2007"),
x="gdpPercap",
y="lifeExp",
size="pop",
color="continent",
hover_name="country",
log_x=True,
size_max=60,
)

tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
with tab1:
st.plotly_chart(fig, use_container_width=use_container_width, theme="streamlit")
with tab2:
st.plotly_chart(fig, use_container_width=use_container_width, theme=None)


try:
get_chart(use_container_width=True)
except Exception as e:
st.exception(e)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import plotly.express as px
import plotly.graph_objects as go
import streamlit as st


@st.cache_data
def get_chart_1111(use_conatiner_width: bool):
st.subheader("Define a custom colorscale")
df = px.data.iris() # replace with your own data source
fig = px.scatter(
df,
x="sepal_width",
y="sepal_length",
color="sepal_length",
color_continuous_scale="reds",
)

tab1, tab2 = st.tabs(["Streamlit theme (default)", "Plotly native theme"])
with tab1:
st.plotly_chart(fig, use_conatiner_width=use_conatiner_width, theme="streamlit")
with tab2:
st.plotly_chart(fig, use_conatiner_width=use_conatiner_width, theme=None)


try:
get_chart_1111(use_conatiner_width=True)
except Exception as e:
st.exception(e)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import streamlit as st
from vega_datasets import data


@st.cache_data
def get_chart(use_container_width: bool):
source = data.cars()

chart = {
"mark": "point",
"encoding": {
"x": {
"field": "Horsepower",
"type": "quantitative",
},
"y": {
"field": "Miles_per_Gallon",
"type": "quantitative",
},
"color": {"field": "Origin", "type": "nominal"},
"shape": {"field": "Origin", "type": "nominal"},
},
}

tab1, tab2 = st.tabs(["Streamlit theme (default)", "Vega-Lite native theme"])

with tab1:
st.vega_lite_chart(
source, chart, use_container_width=use_container_width, theme="streamlit"
)
with tab2:
st.vega_lite_chart(
source, chart, use_container_width=use_container_width, theme=None
)


try:
get_chart(use_container_width=True)
except Exception as e:
st.exception(e)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vega_datasets
plotly==5.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Theme",
"entrypoint": "streamlit_app.py"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit as st

st.text_input("text_input")
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit as st

st.button("click to rerun")

side_effects = []


@st.experimental_memo(experimental_allow_widgets=True)
def foo():
side_effects.append("function ran")
r = st.radio("radio", ["foo", "bar", "baz", "qux"], index=1)
return r


foo()
st.text(side_effects)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit.components.v1 as components

url = "http://not.a.real.url"
test_component = components.declare_component("test_component", url=url)

test_component()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit.components.v1 as components

html = r"<h1>Hello, Streamlit!</h1>"
components.html(html, width=200, height=500, scrolling=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit.components.v1 as components

src = "http://not.a.real.url"
components.iframe(src, width=200, height=500, scrolling=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit as st

# no need to set it using this since we add ?_stcore_testing=true to the url param
# st.experimental_set_query_params(_stcore_testing="true")
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import streamlit as st

a, b = st.columns(2)
a.selectbox("With label", [])
b.selectbox("", []) # No label
Loading

0 comments on commit ec9d97c

Please sign in to comment.