diff --git a/Makefile b/Makefile index c7b9b3e78..bd5eb8dc1 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ desktop := packages/desktop/build/* kernel := packages/kernel/dist/* stlite-server-wheel := packages/kernel/py/stlite-server/dist/stlite_server-0.1.0-py3-none-any.whl streamlit_proto := streamlit/frontend/lib/src/proto.d.ts -streamlit_wheel := packages/kernel/py/streamlit/lib/dist/streamlit-1.35.0-cp312-none-any.whl +streamlit_wheel := packages/kernel/py/streamlit/lib/dist/streamlit-1.36.0-cp312-none-any.whl streamlit_frontend_lib_prod := streamlit/frontend/lib/dist/* export USE_CONSTRAINTS_FILE := false # https://github.com/streamlit/streamlit/blob/1.27.0/.github/workflows/release.yml#L67-L68 @@ -134,7 +134,7 @@ $(streamlit_wheel): venv $(streamlit_proto) streamlit/lib/streamlit/**/*.py stre exit 1; \ fi && \ cd streamlit && SNOWPARK_CONDA_BUILD=true $(MAKE) distribution && cd .. && \ - pyodide py-compile --keep streamlit/lib/dist/streamlit-1.35.0-py2.py3-none-any.whl && \ + pyodide py-compile --keep streamlit/lib/dist/streamlit-1.36.0-py2.py3-none-any.whl && \ mkdir -p $(dir $(streamlit_wheel)) && \ cp streamlit/lib/dist/$(notdir $(streamlit_wheel)) $(streamlit_wheel) diff --git a/packages/common-react/package.json b/packages/common-react/package.json index 786fc0298..40ee0924b 100644 --- a/packages/common-react/package.json +++ b/packages/common-react/package.json @@ -14,7 +14,7 @@ "check:prettier": "prettier --check ." }, "dependencies": { - "@streamlit/lib": "1.35.0" + "@streamlit/lib": "1.36.0" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.49.0", diff --git a/packages/desktop/bin-src/dump_artifacts/index.ts b/packages/desktop/bin-src/dump_artifacts/index.ts index 182aa4804..a27db6527 100755 --- a/packages/desktop/bin-src/dump_artifacts/index.ts +++ b/packages/desktop/bin-src/dump_artifacts/index.ts @@ -148,7 +148,7 @@ async function installPackages( requirements.push(stliteServerWheel); const streamlitWheel = await prepareLocalWheel( pyodide, - path.join(wheelsDir, "streamlit-1.35.0-cp312-none-any.whl"), + path.join(wheelsDir, "streamlit-1.36.0-cp312-none-any.whl"), ); requirements.push(streamlitWheel); diff --git a/packages/desktop/package.json b/packages/desktop/package.json index 7aa8a7a31..a2d119456 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -73,7 +73,7 @@ "@stlite/common": "^0.59.0", "@stlite/common-react": "^0.59.0", "@stlite/kernel": "^0.59.0", - "@streamlit/app": "1.35.0", + "@streamlit/app": "1.36.0", "@testing-library/react": "^14.1.2", "@testing-library/user-event": "^14.0.0", "@types/jest": "^27.4.3", diff --git a/packages/desktop/scripts/copy_wheels.js b/packages/desktop/scripts/copy_wheels.js index 5a10c3cd8..b93813ae2 100755 --- a/packages/desktop/scripts/copy_wheels.js +++ b/packages/desktop/scripts/copy_wheels.js @@ -22,7 +22,7 @@ async function main() { ); const streamlitWheelPath = path.join( stliteKernelPyDir, - "streamlit/lib/dist/streamlit-1.35.0-cp312-none-any.whl", + "streamlit/lib/dist/streamlit-1.36.0-cp312-none-any.whl", ); // Create the `wheels` directory diff --git a/packages/kernel/package.json b/packages/kernel/package.json index a5599ceb9..e19d58382 100644 --- a/packages/kernel/package.json +++ b/packages/kernel/package.json @@ -34,8 +34,8 @@ "dependencies": { "@jupyterlab/coreutils": "^5.4.2", "@stlite/common": "^0.59.0", - "@streamlit/app": "1.35.0", - "@streamlit/lib": "1.35.0", + "@streamlit/app": "1.36.0", + "@streamlit/lib": "1.36.0", "path-browserify": "^1.0.1" } } diff --git a/packages/kernel/py/stlite-server/poetry.lock b/packages/kernel/py/stlite-server/poetry.lock index 7c4f7a243..e2d675a72 100644 --- a/packages/kernel/py/stlite-server/poetry.lock +++ b/packages/kernel/py/stlite-server/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "altair" @@ -1408,13 +1408,13 @@ files = [ [[package]] name = "streamlit" -version = "1.35.0" +version = "1.36.0" description = "A faster way to build and share data apps" optional = false python-versions = "!=3.9.7,>=3.8" files = [ - {file = "streamlit-1.35.0-py2.py3-none-any.whl", hash = "sha256:e17d1d86830a0d7687c37faf2fe47bffa752d0c95a306e96d7749bd3faa72a5b"}, - {file = "streamlit-1.35.0.tar.gz", hash = "sha256:679d55bb6189743f606abf0696623df0bfd223a6d0c8d96b8d60678d4891d2d6"}, + {file = "streamlit-1.36.0-py2.py3-none-any.whl", hash = "sha256:3399a33ea5faa26c05dd433d142eefe68ade67e9189a9e1d47a1731ae30a1c42"}, + {file = "streamlit-1.36.0.tar.gz", hash = "sha256:a12af9f0eb61ab5832f438336257b1ec20eb29d8e0e0c6b40a79116ba939bc9c"}, ] [package.dependencies] @@ -1423,11 +1423,11 @@ blinker = ">=1.0.0,<2" cachetools = ">=4.0,<6" click = ">=7.0,<9" gitpython = ">=3.0.7,<3.1.19 || >3.1.19,<4" -numpy = ">=1.19.3,<2" -packaging = ">=16.8,<25" +numpy = ">=1.20,<3" +packaging = ">=20,<25" pandas = ">=1.3.0,<3" pillow = ">=7.1.0,<11" -protobuf = ">=3.20,<5" +protobuf = ">=3.20,<6" pyarrow = ">=7.0" pydeck = ">=0.8.0b4,<1" requests = ">=2.27,<3" @@ -1436,7 +1436,7 @@ tenacity = ">=8.1.0,<9" toml = ">=0.10.1,<2" tornado = ">=6.0.3,<7" typing-extensions = ">=4.3.0,<5" -watchdog = {version = ">=2.1.5", markers = "platform_system != \"Darwin\""} +watchdog = {version = ">=2.1.5,<5", markers = "platform_system != \"Darwin\""} [package.extras] snowflake = ["snowflake-connector-python (>=2.8.0)", "snowflake-snowpark-python (>=0.9.0)"] diff --git a/packages/kernel/src/kernel.ts b/packages/kernel/src/kernel.ts index 3818735f1..3f266cb28 100644 --- a/packages/kernel/src/kernel.ts +++ b/packages/kernel/src/kernel.ts @@ -32,7 +32,7 @@ import { assertStreamlitConfig } from "./types"; // https://github.com/pyodide/pyodide/pull/1859 // https://pyodide.org/en/stable/project/changelog.html#micropip import STLITE_SERVER_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/stlite-server/dist/stlite_server-0.1.0-py3-none-any.whl"; // TODO: Extract the import statement to an auto-generated file like `_pypi.ts` in JupyterLite: https://github.com/jupyterlite/jupyterlite/blob/f2ecc9cf7189cb19722bec2f0fc7ff5dfd233d47/packages/pyolite-kernel/src/_pypi.ts -import STREAMLIT_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/streamlit/lib/dist/streamlit-1.35.0-cp312-none-any.whl"; +import STREAMLIT_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/streamlit/lib/dist/streamlit-1.36.0-cp312-none-any.whl"; // Ref: https://github.com/streamlit/streamlit/blob/1.12.2/frontend/src/lib/UriUtil.ts#L32-L33 const FINAL_SLASH_RE = /\/+$/; diff --git a/packages/kernel/vitest.config.ts b/packages/kernel/vitest.config.ts index 980603ae2..368733209 100644 --- a/packages/kernel/vitest.config.ts +++ b/packages/kernel/vitest.config.ts @@ -16,7 +16,7 @@ export default defineConfig({ ), "streamlit.whl": path.resolve( __dirname, - "./py/streamlit/lib/dist/streamlit-1.35.0-cp312-none-any.whl", + "./py/streamlit/lib/dist/streamlit-1.36.0-cp312-none-any.whl", ), }, }, diff --git a/packages/mountable/package.json b/packages/mountable/package.json index 6ce799e90..5f55843ae 100644 --- a/packages/mountable/package.json +++ b/packages/mountable/package.json @@ -31,7 +31,7 @@ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.3", "@stlite/common-react": "^0.59.0", "@stlite/kernel": "^0.59.0", - "@streamlit/app": "1.35.0", + "@streamlit/app": "1.36.0", "@svgr/webpack": "^8.1.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.1.2", diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/annotations-in-altair.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/annotations-in-altair.py new file mode 100644 index 000000000..82e56867f --- /dev/null +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/annotations-in-altair.py @@ -0,0 +1,74 @@ +import streamlit as st +import altair as alt +import pandas as pd +from vega_datasets import data + + +@st.cache_data +def get_data(): + source = data.stocks() + source = source[source.date.gt("2004-01-01")] + return source + + +stock_data = get_data() + +hover = alt.selection_single( + fields=["date"], + nearest=True, + on="mouseover", + empty="none", +) + +lines = ( + alt.Chart(stock_data, title="Evolution of stock prices") + .mark_line() + .encode( + x="date", + y="price", + color="symbol", + ) +) + +points = lines.transform_filter(hover).mark_circle(size=65) + +tooltips = ( + alt.Chart(stock_data) + .mark_rule() + .encode( + x="yearmonthdate(date)", + y="price", + opacity=alt.condition(hover, alt.value(0.3), alt.value(0)), + tooltip=[ + alt.Tooltip("date", title="Date"), + alt.Tooltip("price", title="Price (USD)"), + ], + ) + .add_selection(hover) +) + +data_layer = lines + points + tooltips + + +event_picker = alt.selection_point("events") + + +ANNOTATIONS = [ + ("Sep 01, 2007", 400, "🙂", "Something's going well for GOOG & AAPL."), + ("Nov 01, 2008", 180, "🙂", "The market is recovering."), + ("Dec 01, 2007", 700, "😱", "Something's going wrong for GOOG & AAPL."), + ("Dec 01, 2009", 650, "😱", "A hiccup for GOOG."), +] +annotations_df = pd.DataFrame( + ANNOTATIONS, columns=["date", "y", "marker", "description"] +) +annotations_df.date = pd.to_datetime(annotations_df.date) + +annotation_layer = ( + alt.Chart(annotations_df) + .mark_text(size=20, dx=-8, dy=-10, align="left") + .encode(x="date:T", y=alt.Y("y:Q"), text="marker", tooltip="description") +) + +combined_chart = data_layer + annotation_layer +st.altair_chart(combined_chart, use_container_width=True) \ No newline at end of file diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/charts.bar_chart_horizontal.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/charts.bar_chart_horizontal.py new file mode 100644 index 000000000..5583dbc4b --- /dev/null +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/charts.bar_chart_horizontal.py @@ -0,0 +1,10 @@ +import streamlit as st +from vega_datasets import data + +@st.cache_data +def get_data(): + return data.barley() + +source = get_data() + +st.bar_chart(source, x="variety", y="yield", color="site", horizontal=True) diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/dataframe-row-selections.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/dataframe-row-selections.py new file mode 100644 index 000000000..407f83a3c --- /dev/null +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/dataframe-row-selections.py @@ -0,0 +1,96 @@ +import random + +import numpy as np +import pandas as pd +import streamlit as st + + +@st.cache_data +def get_profile_dataset(number_of_items: int = 20, seed: int = 0) -> pd.DataFrame: + from faker import Faker + + new_data = [] + + 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"], + "daily_activity": np.random.rand(25), + "activity": np.random.randint(2, 90, size=12), + } + ) + + profile_df = pd.DataFrame(new_data) + return profile_df + + +column_configuration = { + "name": st.column_config.TextColumn( + "Name", help="The name of the user", max_chars=100, width="medium" + ), + "avatar": st.column_config.ImageColumn("Avatar", help="The user's avatar"), + "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, + ), +} + +select, compare = st.tabs(["Select members", "Compare selected"]) + +with select: + st.header("All members") + + df = get_profile_dataset() + + event = st.dataframe( + df, + column_config=column_configuration, + use_container_width=True, + hide_index=True, + on_select="rerun", + selection_mode="multi-row", + ) + + st.header("Selected members") + people = event.selection.rows + filtered_df = df.iloc[people] + st.dataframe( + filtered_df, + column_config=column_configuration, + use_container_width=True, + ) + +with compare: + activity_df = {} + for person in people: + activity_df[df.iloc[person]["name"]] = df.iloc[person]["activity"] + activity_df = pd.DataFrame(activity_df) + + daily_activity_df = {} + for person in people: + daily_activity_df[df.iloc[person]["name"]] = df.iloc[person]["daily_activity"] + daily_activity_df = pd.DataFrame(daily_activity_df) + + if len(people) > 0: + st.header("Daily activity comparison") + st.bar_chart(daily_activity_df) + st.header("Yearly activity comparison") + st.line_chart(activity_df) + else: + st.markdown("No members selected.") diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment.py index 03dd9791b..e2f7fa183 100644 --- a/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment.py +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment.py @@ -1,7 +1,7 @@ import streamlit as st -if "script_runs" not in st.session_state: - st.session_state.script_runs = 0 +if "app_runs" not in st.session_state: + st.session_state.app_runs = 0 st.session_state.fragment_runs = 0 @@ -12,8 +12,8 @@ def fragment(): st.write(f"Fragment says it ran {st.session_state.fragment_runs} times.") -st.session_state.script_runs += 1 +st.session_state.app_runs += 1 fragment() -st.button("Rerun full script") -st.write(f"Full script says it ran {st.session_state.script_runs} times.") -st.write(f"Full script sees that fragment ran {st.session_state.fragment_runs} times.") +st.button("Rerun full app") +st.write(f"Full app says it ran {st.session_state.app_runs} times.") +st.write(f"Full app sees that fragment ran {st.session_state.fragment_runs} times.") diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment_balloon.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment_balloon.py new file mode 100644 index 000000000..be303441d --- /dev/null +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/execution.fragment_balloon.py @@ -0,0 +1,14 @@ +import streamlit as st +import asyncio + + +@st.experimental_fragment +def release_the_balloons(): + st.button("Release the balloons", help="Fragment rerun") + st.balloons() + + +with st.spinner("Inflating balloons..."): + await asyncio.sleep(5) +release_the_balloons() +st.button("Inflate more balloons", help="Full rerun") diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/layout.columns_bottom_widgets.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/layout.columns_bottom_widgets.py new file mode 100644 index 000000000..9ce155c3b --- /dev/null +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/layout.columns_bottom_widgets.py @@ -0,0 +1,7 @@ +import streamlit as st + +left, middle, right = st.columns(3, vertical_alignment="bottom") + +left.text_input("Write something") +middle.button("Click me", use_container_width=True) +right.checkbox("Check me") \ No newline at end of file diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/layout.columns_vertical_alignment.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/layout.columns_vertical_alignment.py new file mode 100644 index 000000000..f4e0512e2 --- /dev/null +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/layout.columns_vertical_alignment.py @@ -0,0 +1,14 @@ +import streamlit as st +import numpy as np + +vertical_alignment = st.selectbox( + "Vertical alignment", ["top", "center", "bottom"], index=2 +) + +left, middle, right = st.columns(3, vertical_alignment=vertical_alignment) +left.image("https://static.streamlit.io/examples/cat.jpg") +left.markdown("By [@phonvanna](https://unsplash.com/photos/0g7BJEXq7sU)") +middle.image("https://static.streamlit.io/examples/dog.jpg") +middle.markdown("By [@shotbyrain](https://unsplash.com/photos/rmkIqi_C3cA)") +right.image("https://static.streamlit.io/examples/owl.jpg") +right.markdown("By [@zmachacek](https://unsplash.com/photos/ZN4CzqizIyI)") diff --git a/packages/sharing-editor/public/samples/011_component_gallery/pages/utilities.html.py b/packages/sharing-editor/public/samples/011_component_gallery/pages/utilities.html.py index 4e72600e9..d03f75974 100644 --- a/packages/sharing-editor/public/samples/011_component_gallery/pages/utilities.html.py +++ b/packages/sharing-editor/public/samples/011_component_gallery/pages/utilities.html.py @@ -1,11 +1,3 @@ import streamlit as st -code = """ - -""" -st.html(code) -st.markdown("Lorem ipsum") +st.html("
Oops!
") diff --git a/packages/sharing-editor/public/samples/012_hello/agri.csv.gz b/packages/sharing-editor/public/samples/012_hello/agri.csv.gz new file mode 100644 index 000000000..14f9209f0 Binary files /dev/null and b/packages/sharing-editor/public/samples/012_hello/agri.csv.gz differ diff --git a/packages/sharing-editor/public/samples/012_hello/hello.py b/packages/sharing-editor/public/samples/012_hello/hello.py new file mode 100644 index 000000000..dd3e6a665 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_hello/hello.py @@ -0,0 +1,236 @@ +import streamlit as st + + +async def intro(): + import streamlit as st + + st.write("# Welcome to Streamlit! 👋") + st.sidebar.success("Select a demo above.") + + st.markdown( + """ + Streamlit is an open-source app framework built specifically for + Machine Learning and Data Science projects. + + **👈 Select a demo from the dropdown on the left** to see some examples + of what Streamlit can do! + + ### Want to learn more? + + - Check out [streamlit.io](https://streamlit.io) + - Jump into our [documentation](https://docs.streamlit.io) + - Ask a question in our [community + forums](https://discuss.streamlit.io) + + ### See more complex demos + + - Use a neural net to [analyze the Udacity Self-driving Car Image + Dataset](https://github.com/streamlit/demo-self-driving) + - Explore a [New York City rideshare dataset](https://github.com/streamlit/demo-uber-nyc-pickups) + """ + ) + + +async def mapping_demo(): + from urllib.error import URLError + + import pandas as pd + import pydeck as pdk + import streamlit as st + + st.markdown(f"# {list(page_names_to_funcs.keys())[2]}") + st.write( + """ + This demo shows how to use +[`st.pydeck_chart`](https://docs.streamlit.io/develop/api-reference/charts/st.pydeck_chart) +to display geospatial data. +""" + ) + + @st.cache_data + def from_data_file(filename): + url = ( + "http://raw.githubusercontent.com/streamlit/" + "example-data/master/hello/v1/%s" % filename + ) + return pd.read_json(url) + + try: + ALL_LAYERS = { + "Bike Rentals": pdk.Layer( + "HexagonLayer", + data=from_data_file("bike_rental_stats.json"), + get_position=["lon", "lat"], + radius=200, + elevation_scale=4, + elevation_range=[0, 1000], + extruded=True, + ), + "Bart Stop Exits": pdk.Layer( + "ScatterplotLayer", + data=from_data_file("bart_stop_stats.json"), + get_position=["lon", "lat"], + get_color=[200, 30, 0, 160], + get_radius="[exits]", + radius_scale=0.05, + ), + "Bart Stop Names": pdk.Layer( + "TextLayer", + data=from_data_file("bart_stop_stats.json"), + get_position=["lon", "lat"], + get_text="name", + get_color=[0, 0, 0, 200], + get_size=15, + get_alignment_baseline="'bottom'", + ), + "Outbound Flow": pdk.Layer( + "ArcLayer", + data=from_data_file("bart_path_stats.json"), + get_source_position=["lon", "lat"], + get_target_position=["lon2", "lat2"], + get_source_color=[200, 30, 0, 160], + get_target_color=[200, 30, 0, 160], + auto_highlight=True, + width_scale=0.0001, + get_width="outbound", + width_min_pixels=3, + width_max_pixels=30, + ), + } + st.sidebar.markdown("### Map Layers") + selected_layers = [ + layer + for layer_name, layer in ALL_LAYERS.items() + if st.sidebar.checkbox(layer_name, True) + ] + if selected_layers: + st.pydeck_chart( + pdk.Deck( + map_style="mapbox://styles/mapbox/light-v9", + initial_view_state={ + "latitude": 37.76, + "longitude": -122.4, + "zoom": 11, + "pitch": 50, + }, + layers=selected_layers, + ) + ) + else: + st.error("Please choose at least one layer above.") + except URLError as e: + st.error( + """ + **This demo requires internet access.** + + Connection error: %s + """ + % e.reason + ) + + +async def plotting_demo(): + import asyncio + + import numpy as np + import streamlit as st + + st.markdown(f"# {list(page_names_to_funcs.keys())[1]}") + st.write( + """ + This demo illustrates a combination of plotting and animation with +Streamlit. We're generating a bunch of random numbers in a loop for around +5 seconds. Enjoy! +""" + ) + + progress_bar = st.sidebar.progress(0) + status_text = st.sidebar.empty() + last_rows = np.random.randn(1, 1) + chart = st.line_chart(last_rows) + + for i in range(1, 101): + new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0) + status_text.text("%i%% Complete" % i) + chart.add_rows(new_rows) + progress_bar.progress(i) + last_rows = new_rows + await asyncio.sleep(0.05) + + progress_bar.empty() + + # Streamlit widgets automatically run the script from top to bottom. Since + # this button is not connected to any other logic, it just causes a plain + # rerun. + st.button("Re-run") + + +async def data_frame_demo(): + from urllib.error import URLError + + import altair as alt + import pandas as pd + import streamlit as st + + st.markdown(f"# {list(page_names_to_funcs.keys())[3]}") + st.write( + """ + This demo shows how to use `st.write` to visualize Pandas DataFrames. + +(Data courtesy of the [UN Data Explorer](http://data.un.org/Explorer.aspx).) +""" + ) + + @st.cache_data + def get_UN_data(): + # AWS_BUCKET_URL = "http://streamlit-demo-data.s3-us-west-2.amazonaws.com" + # df = pd.read_csv(AWS_BUCKET_URL + "/agri.csv.gz") + df = pd.read_csv("./agri.csv.gz") + return df.set_index("Region") + + try: + df = get_UN_data() + countries = st.multiselect( + "Choose countries", list(df.index), ["China", "United States of America"] + ) + if not countries: + st.error("Please select at least one country.") + else: + data = df.loc[countries] + data /= 1000000.0 + st.write("### Gross Agricultural Production ($B)", data.sort_index()) + + data = data.T.reset_index() + data = pd.melt(data, id_vars=["index"]).rename( + columns={"index": "year", "value": "Gross Agricultural Product ($B)"} + ) + chart = ( + alt.Chart(data) + .mark_area(opacity=0.3) + .encode( + x="year:T", + y=alt.Y("Gross Agricultural Product ($B):Q", stack=None), + color="Region:N", + ) + ) + st.altair_chart(chart, use_container_width=True) + except URLError as e: + st.error( + """ + **This demo requires internet access.** + + Connection error: %s + """ + % e.reason + ) + + +page_names_to_funcs = { + "—": intro, + "Plotting Demo": plotting_demo, + "Mapping Demo": mapping_demo, + "DataFrame Demo": data_frame_demo, +} + +demo_name = st.sidebar.selectbox("Choose a demo", page_names_to_funcs.keys()) +await page_names_to_funcs[demo_name]() diff --git a/packages/sharing-editor/public/samples/012_hello/requirements.txt b/packages/sharing-editor/public/samples/012_hello/requirements.txt new file mode 100644 index 000000000..96c8bd4b2 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_hello/requirements.txt @@ -0,0 +1,10 @@ +pandas +plotly +bokeh +graphviz +requests +matplotlib +numpy +scipy +altair +pydeck diff --git a/packages/sharing-editor/public/samples/012_hello/stlite.json b/packages/sharing-editor/public/samples/012_hello/stlite.json new file mode 100644 index 000000000..d2fe7828a --- /dev/null +++ b/packages/sharing-editor/public/samples/012_hello/stlite.json @@ -0,0 +1,4 @@ +{ + "title": "Hello", + "entrypoint": "hello.py" +} diff --git a/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/README.md b/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/README.md index 093e322c6..b31353baf 100644 --- a/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/README.md +++ b/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/README.md @@ -1,7 +1,7 @@ ## Streamlit Hello demo This sample app is a copy of the `tutorials/custom-navigation` demo. -The source files were copied from https://github.com/streamlit/docs/tree/4f1c7ce444b6c3e0a1bba473199c9ddb42ed6866/python/api-examples-source +The source files were copied from https://github.com/streamlit/docs/tree/dff6f40ea4ec1c5d2f7052db30348945a93dc9db/python/api-examples-source ## License diff --git a/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/requirements.txt b/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/requirements.txt deleted file mode 100644 index 12a470652..000000000 --- a/packages/sharing-editor/public/samples/012_tutorials_custom-navigation/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -streamlit diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/README.md b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/README.md new file mode 100644 index 000000000..37a2320f5 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/README.md @@ -0,0 +1,11 @@ +## Streamlit Hello demo + +This sample app is a copy of the `tutorials/dynamic-navigation` demo. +The source files were copied from https://github.com/streamlit/docs/tree/dff6f40ea4ec1c5d2f7052db30348945a93dc9db/python/api-examples-source + +## License + +As written above, the source files are copied from `https://github.com/streamlit/docs`, +therefore, the license applied to the source, the Apache-2.0 license, is also applied to this sample. + +See https://github.com/streamlit/docs/blob/main/LICENSE diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/admin/admin_1.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/admin/admin_1.py new file mode 100644 index 000000000..9ea5c67c1 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/admin/admin_1.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Admin 1") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/admin/admin_2.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/admin/admin_2.py new file mode 100644 index 000000000..cdac57a88 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/admin/admin_2.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Admin 2") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/images/horizontal_blue.png b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/images/horizontal_blue.png new file mode 100644 index 000000000..05a00969d Binary files /dev/null and b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/images/horizontal_blue.png differ diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/images/icon_blue.png b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/images/icon_blue.png new file mode 100644 index 000000000..96bce1171 Binary files /dev/null and b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/images/icon_blue.png differ diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/request/request_1.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/request/request_1.py new file mode 100644 index 000000000..0b177a60e --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/request/request_1.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Request 1") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/request/request_2.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/request/request_2.py new file mode 100644 index 000000000..659efb5ff --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/request/request_2.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Request 2") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/respond/respond_1.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/respond/respond_1.py new file mode 100644 index 000000000..652a106ea --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/respond/respond_1.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Respond 1") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/respond/respond_2.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/respond/respond_2.py new file mode 100644 index 000000000..fc987ca3b --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/respond/respond_2.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Respond 2") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/settings.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/settings.py new file mode 100644 index 000000000..bd2cbbef4 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/settings.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.header("Settings") +st.write(f"You are logged in as {st.session_state.role}.") diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/stlite.json b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/stlite.json new file mode 100644 index 000000000..32d4f375c --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/stlite.json @@ -0,0 +1,4 @@ +{ + "title": "Tutorials/Dynamic Navigation", + "entrypoint": "streamlit_app.py" +} diff --git a/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/streamlit_app.py b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/streamlit_app.py new file mode 100644 index 000000000..c5ff7d946 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_dynamic-navigation/streamlit_app.py @@ -0,0 +1,78 @@ +import streamlit as st + +if "role" not in st.session_state: + st.session_state.role = None + +ROLES = [None, "Requester", "Responder", "Admin"] + + +def login(): + + st.header("Log in") + role = st.selectbox("Choose your role", ROLES) + + if st.button("Log in"): + st.session_state.role = role + st.rerun() + + +def logout(): + st.session_state.role = None + st.rerun() + + +role = st.session_state.role + +logout_page = st.Page(logout, title="Log out", icon=":material/logout:") +settings = st.Page("settings.py", title="Settings", icon=":material/settings:") +request_1 = st.Page( + "request/request_1.py", + title="Request 1", + icon=":material/help:", + default=(role == "Requester"), +) +request_2 = st.Page( + "request/request_2.py", title="Request 2", icon=":material/bug_report:" +) +respond_1 = st.Page( + "respond/respond_1.py", + title="Respond 1", + icon=":material/healing:", + default=(role == "Responder"), +) +respond_2 = st.Page( + "respond/respond_2.py", title="Respond 2", icon=":material/handyman:" +) +admin_1 = st.Page( + "admin/admin_1.py", + title="Admin 1", + icon=":material/person_add:", + default=(role == "Admin"), +) +admin_2 = st.Page("admin/admin_2.py", title="Admin 2", icon=":material/security:") + +account_pages = [logout_page, settings] +request_pages = [request_1, request_2] +respond_pages = [respond_1, respond_2] +admin_pages = [admin_1, admin_2] + +st.title("Request manager") +st.logo( + "images/horizontal_blue.png", + icon_image="images/icon_blue.png", +) + +page_dict = {} +if st.session_state.role in ["Requester", "Admin"]: + page_dict["Request"] = request_pages +if st.session_state.role in ["Responder", "Admin"]: + page_dict["Respond"] = respond_pages +if st.session_state.role == "Admin": + page_dict["Admin"] = admin_pages + +if len(page_dict) > 0: + pg = st.navigation({"Account": account_pages} | page_dict) +else: + pg = st.navigation([st.Page(login)]) + +pg.run() diff --git a/packages/sharing-editor/public/samples/012_tutorials_fragments/README.md b/packages/sharing-editor/public/samples/012_tutorials_fragments/README.md new file mode 100644 index 000000000..a1fb441d0 --- /dev/null +++ b/packages/sharing-editor/public/samples/012_tutorials_fragments/README.md @@ -0,0 +1,11 @@ +## Streamlit Hello demo + +This sample app is a copy of the `python/api-examples-source/tutorials/execution-flow/fragments` demo. +The source files were copied from https://github.com/streamlit/docs/tree/dff6f40ea4ec1c5d2f7052db30348945a93dc9db/python/api-examples-source + +## License + +As written above, the source files are copied from `https://github.com/streamlit/docs`, +therefore, the license applied to the source, the Apache-2.0 license, is also applied to this sample. + +See https://github.com/streamlit/docs/blob/main/LICENSE diff --git a/packages/sharing-editor/public/samples/012_widget.page_link/requirements.txt b/packages/sharing-editor/public/samples/012_widget.page_link/requirements.txt deleted file mode 100644 index 12a470652..000000000 --- a/packages/sharing-editor/public/samples/012_widget.page_link/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -streamlit diff --git a/packages/sharing/package.json b/packages/sharing/package.json index 94de46341..d2a340915 100644 --- a/packages/sharing/package.json +++ b/packages/sharing/package.json @@ -8,7 +8,7 @@ "@stlite/common-react": "^0.59.0", "@stlite/kernel": "^0.59.0", "@stlite/sharing-common": "^0.59.0", - "@streamlit/app": "1.35.0", + "@streamlit/app": "1.36.0", "@testing-library/react": "^14.1.2", "@testing-library/user-event": "^14.0.0", "@types/jest": "^27.4.3", diff --git a/streamlit b/streamlit index f75e0c0ba..cb38d7969 160000 --- a/streamlit +++ b/streamlit @@ -1 +1 @@ -Subproject commit f75e0c0ba3610d12af45d1061160250780d58ea4 +Subproject commit cb38d796940d0d00e7199b083cdb90aaa2b1bc87