diff --git a/app.py b/app.py new file mode 100644 index 0000000000000000000000000000000000000000..41949fff3c99eb01de8148b40b1b100fb410fdac --- /dev/null +++ b/app.py @@ -0,0 +1,51 @@ +import streamlit as st + +st.title("Streamlit Component Gallery") + +st.image("https://docs.streamlit.io/logo.svg") + +st.markdown(""" +This _stlite_ sample app contains the demos embedded on the Streamlit official document (https://docs.streamlit.io/). + +**👈 Select a demo from the sidebar** to see some examples +of Streamlit built-in components! +""") + +st.markdown(""" +### Notes + +The page files (`pages/*`) are copied from [the Streamlit official document sample directory (`docs/python/api-examples-source`)](https://github.com/streamlit/docs/tree/5e62035f0ea36b211232ae3a5778dcd8ffdcac15/python/api-examples-source) +excluding the sub directories. + +The following files have been changed: +* `widget.download_button.py`: + A local file path in the source code has been rewritten to adjust to the directory structure of this sample app. + +Due to the browser environment limitations, +some components do not work well. +The known issues are listed at https://github.com/whitphx/stlite#limitations. + +### License +As written above, the files `pages/*` are copied from `https://github.com/streamlit/docs` with some modifications, +therefore, the license applied to the source, the Apache-2.0 license, is also applied to this sample as follows. + +#### Apache-2.0 license + +Copyright Streamlit Inc. + +Copyright Yuichiro Tachibana + +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. + +See https://github.com/streamlit/docs/blob/main/LICENSE +""") diff --git a/pages/charts.area_chart.py b/pages/charts.area_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..0e52bb743d5044a7b7b696005426554eddb33a7e --- /dev/null +++ b/pages/charts.area_chart.py @@ -0,0 +1,12 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + 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.audio.py b/pages/charts.audio.py new file mode 100644 index 0000000000000000000000000000000000000000..de5adacf8d43f5420d808e324e0e4ebd2d089fd2 --- /dev/null +++ b/pages/charts.audio.py @@ -0,0 +1,34 @@ +import requests +import streamlit as st + + +@st.experimental_memo +def read_file_from_url(url): + headers = { + "User-Agent": "StreamlitDocs/1.5.0 (https://docs.streamlit.io; hello@streamlit.io)" + } + return requests.get(url, headers=headers).content + + +file_bytes = read_file_from_url( + "https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg" +) + +st.audio(file_bytes, format="audio/ogg") + +st.write( + """ + #### Audio credit: + + Performer: _Muriel Nguyen Xuan_ and _Stéphane Magnenat_ + + Composer: Frédéric Chopin + + License: Creative Commons Attribution-Share Alike 4.0 International, 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license. + https://creativecommons.org/licenses/by-sa/4.0/ + + URL: + https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg + +""" +) diff --git a/pages/charts.bar_chart.py b/pages/charts.bar_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..583a5e0ef57181a4f8b5b77a66873222062fd87f --- /dev/null +++ b/pages/charts.bar_chart.py @@ -0,0 +1,12 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + 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.bokeh_chart.py b/pages/charts.bokeh_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..7a0e18727eafcd0ff1e622452b6cd12a0f33efee --- /dev/null +++ b/pages/charts.bokeh_chart.py @@ -0,0 +1,12 @@ +import streamlit as st +from bokeh.plotting import figure + + +x = [1, 2, 3, 4, 5] +y = [6, 7, 2, 4, 5] + +p = figure(title="simple line example", x_axis_label="x", y_axis_label="y") + +p.line(x, y, legend_label="Trend", line_width=2) + +st.bokeh_chart(p) diff --git a/pages/charts.graphviz_chart.py b/pages/charts.graphviz_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..5f21ba30492e813135f7cc8a68d391f62d19dde7 --- /dev/null +++ b/pages/charts.graphviz_chart.py @@ -0,0 +1,25 @@ +import streamlit as st +import graphviz as graphviz + +@st.experimental_memo +def load_graph(): + # Create a graphlib graph object + graph = graphviz.Digraph() + graph.edge("run", "intr") + graph.edge("intr", "runbl") + graph.edge("runbl", "run") + graph.edge("run", "kernel") + graph.edge("kernel", "zombie") + graph.edge("kernel", "sleep") + graph.edge("kernel", "runmem") + graph.edge("sleep", "swap") + graph.edge("swap", "runswap") + graph.edge("runswap", "new") + graph.edge("runswap", "runmem") + graph.edge("new", "runmem") + graph.edge("sleep", "runmem") + return graph + +graph = load_graph() + +st.graphviz_chart(graph) diff --git a/pages/charts.image.py b/pages/charts.image.py new file mode 100644 index 0000000000000000000000000000000000000000..c2ff175843d39275ba1006434d5279b273044607 --- /dev/null +++ b/pages/charts.image.py @@ -0,0 +1,20 @@ +import streamlit as st + +IMAGE_URL = "https://images.unsplash.com/photo-1548407260-da850faa41e3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1487&q=80" + +st.image(IMAGE_URL, caption="Sunrise by the mountains") + +st.write( + """ + #### Image credit: + + Creator: User _Neil Iris (@neil_ingham)_ from _Unsplash_ + + License: Do whatever you want. + https://unsplash.com/license + + URL: + https://unsplash.com/photos/I2UR7wEftf4 + +""" +) diff --git a/pages/charts.line_chart.py b/pages/charts.line_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..96b3c8d7070b134b903493f01ea6933529367bd8 --- /dev/null +++ b/pages/charts.line_chart.py @@ -0,0 +1,12 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + 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.map.py b/pages/charts.map.py new file mode 100644 index 0000000000000000000000000000000000000000..5ef2b2cfcc355f45effad31a509ca9c185c13c45 --- /dev/null +++ b/pages/charts.map.py @@ -0,0 +1,14 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +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.plotly_chart.py b/pages/charts.plotly_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..fa5e38175a2f7d4a222410e50c5e88818c97056c --- /dev/null +++ b/pages/charts.plotly_chart.py @@ -0,0 +1,24 @@ +import streamlit as st +import plotly.figure_factory as ff +import numpy as np + +@st.experimental_memo +def load_data(): + # Add histogram data + x1 = np.random.randn(200) - 2 + x2 = np.random.randn(200) + x3 = np.random.randn(200) + 2 + + # Group data together + hist_data = [x1, x2, x3] + return hist_data + +hist_data = load_data() + +group_labels = ["Group 1", "Group 2", "Group 3"] + +# Create distplot with custom bin_size +fig = ff.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5]) + +# Plot! +st.plotly_chart(fig) diff --git a/pages/charts.pydeck_chart.py b/pages/charts.pydeck_chart.py new file mode 100644 index 0000000000000000000000000000000000000000..1b35a0dc59bbbb4fc274466d28c6377226593a25 --- /dev/null +++ b/pages/charts.pydeck_chart.py @@ -0,0 +1,45 @@ +import numpy as np +import pandas as pd +import pydeck as pdk +import streamlit as st + + +@st.experimental_memo +def load_data(): + return pd.DataFrame( + np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"] + ) + + +df = load_data() + +st.pydeck_chart( + pdk.Deck( + map_style=None, + initial_view_state=pdk.ViewState( + latitude=37.76, + longitude=-122.4, + zoom=11, + pitch=50, + ), + layers=[ + pdk.Layer( + "HexagonLayer", + data=df, + get_position="[lon, lat]", + radius=200, + elevation_scale=4, + elevation_range=[0, 1000], + pickable=True, + extruded=True, + ), + pdk.Layer( + "ScatterplotLayer", + data=df, + get_position="[lon, lat]", + get_color="[200, 30, 0, 160]", + get_radius=200, + ), + ], + ) +) diff --git a/pages/charts.pyplot.py b/pages/charts.pyplot.py new file mode 100644 index 0000000000000000000000000000000000000000..2de00204bfdf5c7d9bbf80176c41df1489ce0acb --- /dev/null +++ b/pages/charts.pyplot.py @@ -0,0 +1,14 @@ +import streamlit as st +import numpy as np +import matplotlib.pyplot as plt + +@st.experimental_memo +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 new file mode 100644 index 0000000000000000000000000000000000000000..c0d0983cfd55788b5976402e812ca4c096b3d4bf --- /dev/null +++ b/pages/charts.vega_lite_chart.py @@ -0,0 +1,24 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + df = pd.DataFrame(np.random.randn(200, 3), columns=["a", "b", "c"]) + return df + +df = load_data() + +st.vega_lite_chart( + df, + { + "mark": {"type": "circle", "tooltip": True}, + "encoding": { + "x": {"field": "a", "type": "quantitative"}, + "y": {"field": "b", "type": "quantitative"}, + "size": {"field": "c", "type": "quantitative"}, + "color": {"field": "c", "type": "quantitative"}, + }, + }, + use_container_width=True, +) diff --git a/pages/charts.video.py b/pages/charts.video.py new file mode 100644 index 0000000000000000000000000000000000000000..129218399c7830702e99b89ecb874a74aece6e77 --- /dev/null +++ b/pages/charts.video.py @@ -0,0 +1,20 @@ +import streamlit as st + +VIDEO_URL = "https://static.streamlit.io/examples/star.mp4" + +st.video(VIDEO_URL) + +st.write( + """ + #### Video credit: + + Creator: User _fxxu_ from _Pixabay_. + + License: Free for commercial use. No attribution required. + https://pixabay.com/en/service/license/ + + URL: + https://pixabay.com/en/videos/star-long-exposure-starry-sky-sky-6962/ + +""" +) diff --git a/pages/data.dataframe.py b/pages/data.dataframe.py new file mode 100644 index 0000000000000000000000000000000000000000..ffaeb1ffd30d57d7cbd2b7d38c302966dd452975 --- /dev/null +++ b/pages/data.dataframe.py @@ -0,0 +1,12 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + 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 new file mode 100644 index 0000000000000000000000000000000000000000..1f9cda497fabeff883bb2cd2cc7ebb0b2b90854f --- /dev/null +++ b/pages/data.dataframe1.py @@ -0,0 +1,12 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + 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)) diff --git a/pages/data.dataframe2.py b/pages/data.dataframe2.py new file mode 100644 index 0000000000000000000000000000000000000000..162142abbafd0d5420a2d3f64073a5b75b8c13bc --- /dev/null +++ b/pages/data.dataframe2.py @@ -0,0 +1,23 @@ +import pandas as pd +import streamlit as st + + +# Cache the dataframe so it's only loaded once +@st.experimental_memo +def load_data(): + return pd.DataFrame( + { + "first column": [1, 2, 3, 4], + "second column": [10, 20, 30, 40], + } + ) + + +# Boolean to resize the dataframe, stored as a session state variable +st.checkbox("Use container width", value=False, key="use_container_width") + +df = load_data() + +# Display the dataframe and allow the user to stretch the dataframe +# across the full width of the container +st.dataframe(df, use_container_width=st.session_state.use_container_width) diff --git a/pages/data.json.py b/pages/data.json.py new file mode 100644 index 0000000000000000000000000000000000000000..6a383b146d999858eb5475a9975270d497b76594 --- /dev/null +++ b/pages/data.json.py @@ -0,0 +1,5 @@ +import streamlit as st + +st.json( + {"foo": "bar", "baz": "boz", "stuff": ["stuff 1", "stuff 2", "stuff 3", "stuff 5"]} +) diff --git a/pages/data.table.py b/pages/data.table.py new file mode 100644 index 0000000000000000000000000000000000000000..e1c0b882a5ef2fe595f51f28af6605a3dd7d51fc --- /dev/null +++ b/pages/data.table.py @@ -0,0 +1,12 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +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/flower.png b/pages/flower.png new file mode 100644 index 0000000000000000000000000000000000000000..9ec18c559e8d0f5f804a148945cdd5b5af541b86 Binary files /dev/null and b/pages/flower.png differ diff --git a/pages/forms.form1.py b/pages/forms.form1.py new file mode 100644 index 0000000000000000000000000000000000000000..7cee9338f284d063a38bbc25955503fdc6926dd6 --- /dev/null +++ b/pages/forms.form1.py @@ -0,0 +1,13 @@ +import streamlit as st + +with st.form("my_form"): + st.write("Inside the form") + slider_val = st.slider("Form slider") + checkbox_val = st.checkbox("Form checkbox") + + # Every form must have a submit button. + submitted = st.form_submit_button("Submit") + if submitted: + st.write("slider", slider_val, "checkbox", checkbox_val) + +st.write("Outside the form") diff --git a/pages/forms.form2.py b/pages/forms.form2.py new file mode 100644 index 0000000000000000000000000000000000000000..c4eceec41a8bc7e9375c6108c8ccdc288843547f --- /dev/null +++ b/pages/forms.form2.py @@ -0,0 +1,8 @@ +import streamlit as st + +form = st.form("my_form") +form.slider("Inside the form") +st.slider("Outside the form") + +# Now add a submit button to the form: +form.form_submit_button("Submit") diff --git a/pages/layout.columns1.py b/pages/layout.columns1.py new file mode 100644 index 0000000000000000000000000000000000000000..7cb6c9bb1ee3e023e0a103de57e468362e9fa8cd --- /dev/null +++ b/pages/layout.columns1.py @@ -0,0 +1,20 @@ +import streamlit as st + +col1, col2, col3 = st.columns(3) + +with col1: + st.header("A cat") + st.image("https://static.streamlit.io/examples/cat.jpg") + st.markdown("By [@phonvanna](https://unsplash.com/photos/0g7BJEXq7sU)") + + +with col2: + st.header("A dog") + st.image("https://static.streamlit.io/examples/dog.jpg") + st.markdown("By [@shotbyrain](https://unsplash.com/photos/rmkIqi_C3cA)") + + +with col3: + st.header("An owl") + st.image("https://static.streamlit.io/examples/owl.jpg") + st.markdown("By [@zmachacek](https://unsplash.com/photos/ZN4CzqizIyI)") diff --git a/pages/layout.columns2.py b/pages/layout.columns2.py new file mode 100644 index 0000000000000000000000000000000000000000..189832d72d22e477cbc4bc3f284b4b7b2d5eee30 --- /dev/null +++ b/pages/layout.columns2.py @@ -0,0 +1,16 @@ +import streamlit as st +import numpy as np + +@st.experimental_memo +def load_data(): + data = np.random.randn(10, 1) + return data + +col1, col2 = st.columns([3, 1]) +data = load_data() + +col1.subheader("A wide column with a chart") +col1.line_chart(data) + +col2.subheader("A narrow column with the data") +col2.write(data) diff --git a/pages/layout.container1.py b/pages/layout.container1.py new file mode 100644 index 0000000000000000000000000000000000000000..602a931e2cb63a5c1d08433e8cf2cc9a89164ce9 --- /dev/null +++ b/pages/layout.container1.py @@ -0,0 +1,10 @@ +import streamlit as st +import numpy as np +import pandas as pd + +with st.container(): + st.write("This is inside the container") + + # You can call any Streamlit command, including custom components: + st.bar_chart(np.random.randn(50, 3)) +st.write("This is outside the container") diff --git a/pages/layout.container2.py b/pages/layout.container2.py new file mode 100644 index 0000000000000000000000000000000000000000..3ed3fafcc6b0dc78a82ffdea129ef80f6e2aa19f --- /dev/null +++ b/pages/layout.container2.py @@ -0,0 +1,8 @@ +import streamlit as st + +container = st.container() +container.write("This is inside the container") +st.write("This is outside the container") + +# Now insert some more in the container +container.write("This is inside too") diff --git a/pages/layout.expander.py b/pages/layout.expander.py new file mode 100644 index 0000000000000000000000000000000000000000..7eb23994a8da552b2193ec38be9d352fe5ce5c66 --- /dev/null +++ b/pages/layout.expander.py @@ -0,0 +1,14 @@ +import streamlit as st + +st.bar_chart({"d6": [1, 5, 2, 6, 2, 1]}) + +with st.expander("See explanation"): + st.write( + """ + The chart above shows some numbers I picked for you. + I rolled actual dice for these, so they're *guaranteed* to + be random. + """ + ) + st.image("https://static.streamlit.io/examples/dice.jpg", width=200) + st.markdown("Photo by [@brett_jordon](https://unsplash.com/photos/4aB1nGtD_Sg)") diff --git a/pages/layout.tabs1.py b/pages/layout.tabs1.py new file mode 100644 index 0000000000000000000000000000000000000000..e8e8feb4f220635267260c6db68708790570d73f --- /dev/null +++ b/pages/layout.tabs1.py @@ -0,0 +1,14 @@ +import streamlit as st + +tab1, tab2, tab3 = st.tabs(["Cat", "Dog", "Owl"]) +with tab1: + st.header("A cat") + st.image("https://static.streamlit.io/examples/cat.jpg", width=200) + +with tab2: + st.header("A dog") + st.image("https://static.streamlit.io/examples/dog.jpg", width=200) + +with tab3: + st.header("An owl") + st.image("https://static.streamlit.io/examples/owl.jpg", width=200) diff --git a/pages/layout.tabs2.py b/pages/layout.tabs2.py new file mode 100644 index 0000000000000000000000000000000000000000..2104f0ae3d1d185b86c4c2b7a2b3c1724a138f40 --- /dev/null +++ b/pages/layout.tabs2.py @@ -0,0 +1,11 @@ +import streamlit as st +import numpy as np + +tab1, tab2 = st.tabs(["📈 Chart", "🗃 Data"]) +data = np.random.randn(10, 1) + +tab1.subheader("A tab with a chart") +tab1.line_chart(data) + +tab2.subheader("A tab with the data") +tab2.write(data) diff --git a/pages/metric.example1.py b/pages/metric.example1.py new file mode 100644 index 0000000000000000000000000000000000000000..88f4c9ec6c8de1b542fed2818c90642d93d84507 --- /dev/null +++ b/pages/metric.example1.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.metric(label="Temperature", value="70 °F", delta="1.2 °F", delta_color="normal") diff --git a/pages/metric.example2.py b/pages/metric.example2.py new file mode 100644 index 0000000000000000000000000000000000000000..6359a077333568848c8b00ee5b55d53b2e9b31cf --- /dev/null +++ b/pages/metric.example2.py @@ -0,0 +1,6 @@ +import streamlit as st + +col1, col2, col3 = st.columns(3) +col1.metric("Temperature", "70 °F", "1.2 °F") +col2.metric("Wind", "9 mph", "-8%") +col3.metric("Humidity", "86%", "4%") diff --git a/pages/metric.example3.py b/pages/metric.example3.py new file mode 100644 index 0000000000000000000000000000000000000000..f576096fbbe0cd25ecb154be064adeba1b068cf4 --- /dev/null +++ b/pages/metric.example3.py @@ -0,0 +1,4 @@ +import streamlit as st + +st.metric(label="Gas price", value=4, delta=-0.5, delta_color="inverse") +st.metric(label="Active developers", value=123, delta=123, delta_color="off") diff --git a/pages/requirements.txt b/pages/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..8659f85b20c22f0bcbf632f1d7b8dec08b98dff8 --- /dev/null +++ b/pages/requirements.txt @@ -0,0 +1,11 @@ +pandas==1.2.5 +plotly==5.1.0 +bokeh==2.4.3 +graphviz==0.17 +requests==2.22.0 +matplotlib==3.4.1 +numpy==1.22.0 +scipy +altair==4.2.0 +pydeck==0.7.1 +streamlit==1.13.0 \ No newline at end of file diff --git a/pages/text.caption.py b/pages/text.caption.py new file mode 100644 index 0000000000000000000000000000000000000000..af3d55ef7509bf9b8cb8393803eb49531bc736dd --- /dev/null +++ b/pages/text.caption.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.caption('This is a caption') diff --git a/pages/text.code.py b/pages/text.code.py new file mode 100644 index 0000000000000000000000000000000000000000..72f11a2b47086f27565e4fb635750efb1af07ebe --- /dev/null +++ b/pages/text.code.py @@ -0,0 +1,5 @@ +import streamlit as st + +code = """def hello(): + print("Hello, Streamlit!")""" +st.code(code, language="python") diff --git a/pages/text.header.py b/pages/text.header.py new file mode 100644 index 0000000000000000000000000000000000000000..ad87d1884fca4b69d4f0c5fdb2a6f0dd5e364e29 --- /dev/null +++ b/pages/text.header.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.header("This is a header") diff --git a/pages/text.latex.py b/pages/text.latex.py new file mode 100644 index 0000000000000000000000000000000000000000..e583777613833519075f262917812f6a42b4e4bc --- /dev/null +++ b/pages/text.latex.py @@ -0,0 +1,9 @@ +import streamlit as st + +st.latex( + r""" + a + ar + a r^2 + a r^3 + \cdots + a r^{n-1} = + \sum_{k=0}^{n-1} ar^k = + a \left(\frac{1-r^{n}}{1-r}\right) + """ +) diff --git a/pages/text.markdown.py b/pages/text.markdown.py new file mode 100644 index 0000000000000000000000000000000000000000..b883b0bbabc3ff43a9157951cd72d2d102d556a8 --- /dev/null +++ b/pages/text.markdown.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.markdown("Streamlit is **_really_ cool**.") diff --git a/pages/text.subheader.py b/pages/text.subheader.py new file mode 100644 index 0000000000000000000000000000000000000000..1bec0b1c222cc447a236c65554eddb386591fac1 --- /dev/null +++ b/pages/text.subheader.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.subheader("This is a subheader") diff --git a/pages/text.text.py b/pages/text.text.py new file mode 100644 index 0000000000000000000000000000000000000000..8a37c90123ddc8e20ac31cd43de6f2ecf239fbfb --- /dev/null +++ b/pages/text.text.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.text("This is some text.") diff --git a/pages/text.title.py b/pages/text.title.py new file mode 100644 index 0000000000000000000000000000000000000000..38586b146963b422adf36b31e2a91350608ef51c --- /dev/null +++ b/pages/text.title.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.title("This is a title") diff --git a/pages/text.write1.py b/pages/text.write1.py new file mode 100644 index 0000000000000000000000000000000000000000..5cf71394251f670dc7ffff6c418a3e2239cc545d --- /dev/null +++ b/pages/text.write1.py @@ -0,0 +1,3 @@ +import streamlit as st + +st.write("Hello, *World!* :sunglasses:") diff --git a/pages/text.write2.py b/pages/text.write2.py new file mode 100644 index 0000000000000000000000000000000000000000..e68dbb4827ba543259420c3922b7eccc068775bf --- /dev/null +++ b/pages/text.write2.py @@ -0,0 +1,7 @@ +import streamlit as st +import pandas as pd + +st.write(1234) +st.write( + pd.DataFrame({"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]}) +) diff --git a/pages/text.write3.py b/pages/text.write3.py new file mode 100644 index 0000000000000000000000000000000000000000..1e8de7bc6441558f6a87caf2f277028e9002e4c4 --- /dev/null +++ b/pages/text.write3.py @@ -0,0 +1,13 @@ +import streamlit as st +import pandas as pd + +@st.experimental_memo +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/widget.button.py b/pages/widget.button.py new file mode 100644 index 0000000000000000000000000000000000000000..07d1996441be43e8458cf3f300ca5d86e63f5886 --- /dev/null +++ b/pages/widget.button.py @@ -0,0 +1,6 @@ +import streamlit as st + +if st.button("Say hello"): + st.write("Why hello there") +else: + st.write("Goodbye") diff --git a/pages/widget.checkbox.py b/pages/widget.checkbox.py new file mode 100644 index 0000000000000000000000000000000000000000..5b6850f182cf71f04607f8b99f73a4af295690c0 --- /dev/null +++ b/pages/widget.checkbox.py @@ -0,0 +1,5 @@ +import streamlit as st + +agree = st.checkbox("I agree") +if agree: + st.write("Great!") diff --git a/pages/widget.color_picker.py b/pages/widget.color_picker.py new file mode 100644 index 0000000000000000000000000000000000000000..f2180c3051e4ce873139f1cc0ba26a54e0b3835c --- /dev/null +++ b/pages/widget.color_picker.py @@ -0,0 +1,4 @@ +import streamlit as st + +color = st.color_picker('Pick A Color', '#00f900') +st.write('The current color is', color) diff --git a/pages/widget.date_input.py b/pages/widget.date_input.py new file mode 100644 index 0000000000000000000000000000000000000000..713f26f8699befb044299007a79b0e0a5d63cf4b --- /dev/null +++ b/pages/widget.date_input.py @@ -0,0 +1,5 @@ +import streamlit as st +import datetime + +d = st.date_input("When's your birthday", datetime.date(2020, 8, 11)) +st.write("Your birthday is:", d) diff --git a/pages/widget.download_button.py b/pages/widget.download_button.py new file mode 100644 index 0000000000000000000000000000000000000000..76e90180793918234928ac0cb80c36e4ff4b9377 --- /dev/null +++ b/pages/widget.download_button.py @@ -0,0 +1,41 @@ +import streamlit as st +import pandas as pd +import numpy as np + +@st.experimental_memo +def load_data(): + data = pd.DataFrame( + np.random.randn(1000, 2), + columns=['a', 'b']) + + return data + +@st.experimental_memo +def convert_df(df): + # IMPORTANT: Cache the conversion to prevent computation on every rerun + 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', + ) + +text_contents = '''This is some text''' +st.download_button('Download some text', text_contents) + +binary_contents = b'example content' +# Defaults to 'application/octet-stream' +st.download_button('Download binary file', binary_contents) + +with open("pages/flower.png", "rb") as file: + btn = st.download_button( + label="Download image", + data=file, + file_name="flower.png", + mime="image/png" + ) diff --git a/pages/widget.file_uploader.py b/pages/widget.file_uploader.py new file mode 100644 index 0000000000000000000000000000000000000000..6ed38bfd1a1a1837f5d0530674f2012a7b6ab959 --- /dev/null +++ b/pages/widget.file_uploader.py @@ -0,0 +1,6 @@ +import streamlit as st + +uploaded_files = st.file_uploader("Choose a file", accept_multiple_files=True) + +for uploaded_file in uploaded_files: + st.write("filename:", uploaded_file.name) diff --git a/pages/widget.multiselect.py b/pages/widget.multiselect.py new file mode 100644 index 0000000000000000000000000000000000000000..be5632cdbf570324ce57575c3fc75468b3936b66 --- /dev/null +++ b/pages/widget.multiselect.py @@ -0,0 +1,8 @@ +import streamlit as st + +options = st.multiselect( + 'What are your favorite colors', + ['Green', 'Yellow', 'Red', 'Blue'], + ['Yellow', 'Red']) + +st.write('You selected:', options) diff --git a/pages/widget.number_input.py b/pages/widget.number_input.py new file mode 100644 index 0000000000000000000000000000000000000000..ff4da406bee30164c3140534d8c43b2745e3a26e --- /dev/null +++ b/pages/widget.number_input.py @@ -0,0 +1,4 @@ +import streamlit as st + +number = st.number_input('Insert a number') +st.write('The current number is ', number) diff --git a/pages/widget.radio.py b/pages/widget.radio.py new file mode 100644 index 0000000000000000000000000000000000000000..24ac59c854274fd8a170b5b247fcaf9b8fcc24a7 --- /dev/null +++ b/pages/widget.radio.py @@ -0,0 +1,8 @@ +import streamlit as st + +genre = st.radio("What's your favorite movie genre", ("Comedy", "Drama", "Documentary")) + +if genre == "Comedy": + st.write("You selected comedy.") +else: + st.write("You didn't select comedy.") diff --git a/pages/widget.radio1.py b/pages/widget.radio1.py new file mode 100644 index 0000000000000000000000000000000000000000..1411ca1a6a2eca5b2329fe45f67aca833a89f8f8 --- /dev/null +++ b/pages/widget.radio1.py @@ -0,0 +1,23 @@ +import streamlit as st + +# Store the initial value of widgets in session state +if "visibility" not in st.session_state: + st.session_state.visibility = "visible" + st.session_state.disabled = False + st.session_state.horizontal = False + +col1, col2 = st.columns(2) + +with col1: + st.checkbox("Disable radio widget", key="disabled") + st.checkbox("Orient radio options horizontally", key="horizontal") + +with col2: + st.radio( + "Set label visibility 👇", + ["visible", "hidden", "collapsed"], + key="visibility", + label_visibility=st.session_state.visibility, + disabled=st.session_state.disabled, + horizontal=st.session_state.horizontal, + ) diff --git a/pages/widget.select_slider.py b/pages/widget.select_slider.py new file mode 100644 index 0000000000000000000000000000000000000000..61c31a35a81ee99fa3ab38ddaba25233f639beb2 --- /dev/null +++ b/pages/widget.select_slider.py @@ -0,0 +1,14 @@ +import streamlit as st + +color = st.select_slider( + 'Select a color of the rainbow', + options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']) + +st.write('My favorite color is', color) + +start_color, end_color = st.select_slider( + 'Select a range of color wavelength', + options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'], + value=('red', 'blue')) + +st.write('You selected wavelengths between', start_color, 'and', end_color) diff --git a/pages/widget.selectbox.py b/pages/widget.selectbox.py new file mode 100644 index 0000000000000000000000000000000000000000..c95b8454c386ad5249340ba4c5c6afa723cb4691 --- /dev/null +++ b/pages/widget.selectbox.py @@ -0,0 +1,7 @@ +import streamlit as st + +option = st.selectbox( + "How would you like to be contacted?", ("Email", "Home phone", "Mobile phone") +) + +st.write("You selected:", option) diff --git a/pages/widget.selectbox1.py b/pages/widget.selectbox1.py new file mode 100644 index 0000000000000000000000000000000000000000..ea3dc1ba1cf9bc28fb97a3ade1030d53e8c97e02 --- /dev/null +++ b/pages/widget.selectbox1.py @@ -0,0 +1,24 @@ +import streamlit as st + +# Store the initial value of widgets in session state +if "visibility" not in st.session_state: + st.session_state.visibility = "visible" + st.session_state.disabled = False + +col1, col2 = st.columns(2) + +with col1: + st.checkbox("Disable selectbox widget", key="disabled") + st.radio( + "Set selectbox label visibility 👉", + key="visibility", + options=["visible", "hidden", "collapsed"], + ) + +with col2: + option = st.selectbox( + "How would you like to be contacted?", + ("Email", "Home phone", "Mobile phone"), + label_visibility=st.session_state.visibility, + disabled=st.session_state.disabled, + ) diff --git a/pages/widget.slider.py b/pages/widget.slider.py new file mode 100644 index 0000000000000000000000000000000000000000..1986d5bfd89f485ce4aa75d544d3f748b55a43c2 --- /dev/null +++ b/pages/widget.slider.py @@ -0,0 +1,23 @@ +import streamlit as st +from datetime import time, datetime + +st.subheader("Slider") +age = st.slider("How old are you?", 0, 130, 25) +st.write("I'm ", age, "years old.") + +st.subheader("Range slider") +values = st.slider("Select a range of values", 0.0, 100.0, (25.0, 75.0)) +st.write("Values:", values) + +st.subheader("Time slider") +appointment = st.slider( + "Schedule your appointment:", + value=(time(11, 30), time(12, 45)), +) +st.write("You're scheduled for:", appointment) + +st.subheader("Datetime slider") +start_time = st.slider( + "When do you start?", value=datetime(2020, 1, 1, 9, 30), format="MM/DD/YY - hh:mm" +) +st.write("Start time:", start_time) diff --git a/pages/widget.text_area.py b/pages/widget.text_area.py new file mode 100644 index 0000000000000000000000000000000000000000..cb599fb3c14826bf091de26a91d443db99f1d945 --- /dev/null +++ b/pages/widget.text_area.py @@ -0,0 +1,17 @@ +import streamlit as st + + +def run_sentiment_analysis(x): + return "dramatic" + + +txt = st.text_area( + "Text to analyze", + """ + It was the best of times, it was the worst of times, it was the age of + wisdom, it was the age of foolishness, it was the epoch of belief, it was + the epoch of incredulity, it was the season of Light, it was the season of + Darkness, it was the spring of hope, it was the winter of despair, (...) + """, +) +st.write("Sentiment:", run_sentiment_analysis(txt)) diff --git a/pages/widget.text_input.py b/pages/widget.text_input.py new file mode 100644 index 0000000000000000000000000000000000000000..8fcbf6f7157022935dbdc9752e3e4ef240944540 --- /dev/null +++ b/pages/widget.text_input.py @@ -0,0 +1,4 @@ +import streamlit as st + +title = st.text_input("Movie title", "Life of Brian") +st.write("The current movie title is", title) diff --git a/pages/widget.text_input1.py b/pages/widget.text_input1.py new file mode 100644 index 0000000000000000000000000000000000000000..c351b229f23322a1f088288d67a833db41129e66 --- /dev/null +++ b/pages/widget.text_input1.py @@ -0,0 +1,32 @@ +import streamlit as st + +# Store the initial value of widgets in session state +if "visibility" not in st.session_state: + st.session_state.visibility = "visible" + st.session_state.disabled = False + +col1, col2 = st.columns(2) + +with col1: + st.checkbox("Disable text input widget", key="disabled") + st.radio( + "Set text input label visibility 👉", + key="visibility", + options=["visible", "hidden", "collapsed"], + ) + st.text_input( + "Placeholder for the other text input widget", + "This is a placeholder", + key="placeholder", + ) + +with col2: + text_input = st.text_input( + "Enter some text 👇", + label_visibility=st.session_state.visibility, + disabled=st.session_state.disabled, + placeholder=st.session_state.placeholder, + ) + + if text_input: + st.write("You entered: ", text_input) diff --git a/pages/widget.time_input.py b/pages/widget.time_input.py new file mode 100644 index 0000000000000000000000000000000000000000..5fc6596e33f095109f8ead4a914859675aceb138 --- /dev/null +++ b/pages/widget.time_input.py @@ -0,0 +1,5 @@ +import streamlit as st +import datetime + +t = st.time_input("Set an alarm for", datetime.time(8, 45)) +st.write("Alarm is set for", t) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb349be8f299c73e1d74f718a8fbea77db0a938c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +graphviz +plotly +scipy +matplotlib