cbensimon HF staff commited on
Commit
921ea2e
β€’
1 Parent(s): 1c124af

Streamlit hello

Browse files
README.md CHANGED
@@ -5,7 +5,7 @@ colorFrom: blue
5
  colorTo: green
6
  sdk: streamlit
7
  sdk_version: 1.15.2
8
- app_file: app.py
9
  pinned: false
10
  ---
11
 
 
5
  colorTo: green
6
  sdk: streamlit
7
  sdk_version: 1.15.2
8
+ app_file: hello/Hello.py
9
  pinned: false
10
  ---
11
 
app.py DELETED
@@ -1,159 +0,0 @@
1
- import streamlit as st
2
- import plotly.figure_factory as ff
3
- import numpy as np
4
- import random
5
-
6
-
7
- # This code is different for each deployed app.
8
- CURRENT_THEME = "blue"
9
- IS_DARK_THEME = True
10
- EXPANDER_TEXT = """
11
- This is a custom theme. You can enable it by copying the following code
12
- to `.streamlit/config.toml`:
13
- ```python
14
- [theme]
15
- primaryColor = "#E694FF"
16
- backgroundColor = "#00172B"
17
- secondaryBackgroundColor = "#0083B8"
18
- textColor = "#C6CDD4"
19
- font = "sans-serif"
20
- ```
21
- """
22
-
23
-
24
- # This code is the same for each deployed app.
25
- st.image(
26
- "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/271/artist-palette_1f3a8.png",
27
- width=100,
28
- )
29
-
30
- """
31
- # Try out Theming!
32
- Click on the images below to view this app with different themes.
33
- """
34
-
35
- ""
36
-
37
- THEMES = [
38
- "light",
39
- "dark",
40
- "green",
41
- "blue",
42
- ]
43
- GITHUB_OWNER = "streamlit"
44
-
45
- # Show thumbnails for available themes.
46
- # As html img tags here, so we can add links on them.
47
- cols = st.columns(len(THEMES))
48
- for col, theme in zip(cols, THEMES):
49
-
50
- # Get repo name for this theme (to link to correct deployed app)-
51
- if theme == "light":
52
- repo = "theming-showcase"
53
- else:
54
- repo = f"theming-showcase-{theme}"
55
-
56
- # Set border of current theme to red, otherwise black or white
57
- if theme == CURRENT_THEME:
58
- border_color = "red"
59
- else:
60
- border_color = "lightgrey" if IS_DARK_THEME else "black"
61
-
62
- col.markdown(
63
- #f'<p align=center><a href="https://share.streamlit.io/{GITHUB_OWNER}/{repo}/main"><img style="border: 1px solid {border_color}" alt="{theme}" src="https://raw.githubusercontent.com/{GITHUB_OWNER}/theming-showcase/main/thumbnails/{theme}.png" width=150></a></p>',
64
- f'<p align=center><a href="https://apps.streamlitusercontent.com/{GITHUB_OWNER}/{repo}/main/streamlit_app.py/+/"><img style="border: 1px solid {border_color}" alt="{theme}" src="https://raw.githubusercontent.com/{GITHUB_OWNER}/theming-showcase/main/thumbnails/{theme}.png" width=150></a></p>',
65
- unsafe_allow_html=True,
66
- )
67
- if theme in ["light", "dark"]:
68
- theme_descriptor = theme.capitalize() + " theme"
69
- else:
70
- theme_descriptor = "Custom theme"
71
- col.write(f"<p align=center>{theme_descriptor}</p>", unsafe_allow_html=True)
72
-
73
-
74
- ""
75
- with st.expander("Not loading?"):
76
- st.write(
77
- "You probably played around with themes before and overrode this app's theme. Go to ☰ -> Settings -> Theme and select *Custom Theme*."
78
- )
79
- with st.expander("How can I use this theme in my app?"):
80
- st.write(EXPANDER_TEXT)
81
-
82
- ""
83
- ""
84
-
85
- # Draw some dummy content in main page and sidebar.
86
- def draw_all(
87
- key,
88
- plot=False,
89
- ):
90
- st.write(
91
- """
92
- # Example Widgets
93
-
94
- These widgets don't do anything. But look at all the new colors they got πŸ‘€
95
-
96
- ```python
97
- # First some code.
98
- streamlit = "cool"
99
- theming = "fantastic"
100
- both = "πŸ’₯"
101
- ```
102
- """
103
- )
104
-
105
- st.checkbox("Is this cool or what?", key=str(random.randint(0, 10000)))
106
- st.radio(
107
- "How many balloons?",
108
- ["1 balloon 🎈", "2 balloons 🎈🎈", "3 balloons 🎈🎈🎈"],
109
- key=str(random.randint(0, 10000)),
110
- )
111
- st.button("🀑 Click me", key=str(random.randint(0, 10000)))
112
-
113
- # if plot:
114
- # st.write("Oh look, a plot:")
115
- # x1 = np.random.randn(200) - 2
116
- # x2 = np.random.randn(200)
117
- # x3 = np.random.randn(200) + 2
118
-
119
- # hist_data = [x1, x2, x3]
120
- # group_labels = ["Group 1", "Group 2", "Group 3"]
121
-
122
- # fig = ff.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5])
123
-
124
- # st.plotly_chart(fig, use_container_width=True)
125
-
126
- st.file_uploader("You can now upload with style", key=str(random.randint(0, 10000)))
127
- st.slider(
128
- "From 10 to 11, how cool are themes?", min_value=10, max_value=11, key=str(random.randint(0, 10000))
129
- )
130
- # st.select_slider("Pick a number", [1, 2, 3], key=key)
131
- st.number_input("So many numbers", key=str(random.randint(0, 10000)))
132
- st.text_area("A little writing space for you :)", key=str(random.randint(0, 10000)))
133
- st.text_input("Text input :)", key=str(random.randint(0, 10000)))
134
- st.selectbox(
135
- "My favorite thing in the world is...",
136
- ["Streamlit", "Theming", "Baloooons 🎈 "],
137
- key=str(random.randint(0, 10000)),
138
- )
139
- # st.multiselect("Pick a number", [1, 2, 3], key=key)
140
- # st.color_picker("Colors, colors, colors", key=key)
141
- with st.expander("Expand me!"):
142
- st.write("Hey there! Nothing to see here πŸ‘€ ")
143
- st.write("")
144
- # st.write("That's our progress on theming:")
145
- # st.progress(0.99)
146
- if plot:
147
- st.write("And here's some data and plots")
148
- st.json({"data": [1, 2, 3, 4]})
149
- st.dataframe({"data": [1, 2, 3, 4]})
150
- st.table({"data": [1, 2, 3, 4]})
151
- st.line_chart({"data": [1, 2, 3, 4]})
152
- # st.help(st.write)
153
- st.write("This is the end. Have fun building themes!")
154
-
155
-
156
- draw_all("main", plot=True)
157
-
158
- with st.sidebar:
159
- draw_all("sidebar")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
hello/Hello.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import streamlit as st
16
+ from streamlit.logger import get_logger
17
+
18
+ LOGGER = get_logger(__name__)
19
+
20
+
21
+ def run():
22
+ st.set_page_config(
23
+ page_title="Hello",
24
+ page_icon="πŸ‘‹",
25
+ )
26
+
27
+ st.write("# Welcome to Streamlit! πŸ‘‹")
28
+
29
+ st.sidebar.success("Select a demo above.")
30
+
31
+ st.markdown(
32
+ """
33
+ Streamlit is an open-source app framework built specifically for
34
+ Machine Learning and Data Science projects.
35
+ **πŸ‘ˆ Select a demo from the sidebar** to see some examples
36
+ of what Streamlit can do!
37
+ ### Want to learn more?
38
+ - Check out [streamlit.io](https://streamlit.io)
39
+ - Jump into our [documentation](https://docs.streamlit.io)
40
+ - Ask a question in our [community
41
+ forums](https://discuss.streamlit.io)
42
+ ### See more complex demos
43
+ - Use a neural net to [analyze the Udacity Self-driving Car Image
44
+ Dataset](https://github.com/streamlit/demo-self-driving)
45
+ - Explore a [New York City rideshare dataset](https://github.com/streamlit/demo-uber-nyc-pickups)
46
+ """
47
+ )
48
+
49
+
50
+ if __name__ == "__main__":
51
+ run()
hello/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
hello/pages/0_Animation_Demo.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from typing import Any
16
+
17
+ import numpy as np
18
+
19
+ import streamlit as st
20
+ from streamlit.hello.utils import show_code
21
+
22
+
23
+ def animation_demo() -> None:
24
+
25
+ # Interactive Streamlit elements, like these sliders, return their value.
26
+ # This gives you an extremely simple interaction model.
27
+ iterations = st.sidebar.slider("Level of detail", 2, 20, 10, 1)
28
+ separation = st.sidebar.slider("Separation", 0.7, 2.0, 0.7885)
29
+
30
+ # Non-interactive elements return a placeholder to their location
31
+ # in the app. Here we're storing progress_bar to update it later.
32
+ progress_bar = st.sidebar.progress(0)
33
+
34
+ # These two elements will be filled in later, so we create a placeholder
35
+ # for them using st.empty()
36
+ frame_text = st.sidebar.empty()
37
+ image = st.empty()
38
+
39
+ m, n, s = 960, 640, 400
40
+ x = np.linspace(-m / s, m / s, num=m).reshape((1, m))
41
+ y = np.linspace(-n / s, n / s, num=n).reshape((n, 1))
42
+
43
+ for frame_num, a in enumerate(np.linspace(0.0, 4 * np.pi, 100)):
44
+ # Here were setting value for these two elements.
45
+ progress_bar.progress(frame_num)
46
+ frame_text.text("Frame %i/100" % (frame_num + 1))
47
+
48
+ # Performing some fractal wizardry.
49
+ c = separation * np.exp(1j * a)
50
+ Z = np.tile(x, (n, 1)) + 1j * np.tile(y, (1, m))
51
+ C = np.full((n, m), c)
52
+ M: Any = np.full((n, m), True, dtype=bool)
53
+ N = np.zeros((n, m))
54
+
55
+ for i in range(iterations):
56
+ Z[M] = Z[M] * Z[M] + C[M]
57
+ M[np.abs(Z) > 2] = False
58
+ N[M] = i
59
+
60
+ # Update the image placeholder by calling the image() function on it.
61
+ image.image(1.0 - (N / N.max()), use_column_width=True)
62
+
63
+ # We clear elements by calling empty on them.
64
+ progress_bar.empty()
65
+ frame_text.empty()
66
+
67
+ # Streamlit widgets automatically run the script from top to bottom. Since
68
+ # this button is not connected to any other logic, it just causes a plain
69
+ # rerun.
70
+ st.button("Re-run")
71
+
72
+
73
+ st.set_page_config(page_title="Animation Demo", page_icon="πŸ“Ή")
74
+ st.markdown("# Animation Demo")
75
+ st.sidebar.header("Animation Demo")
76
+ st.write(
77
+ """This app shows how you can use Streamlit to build cool animations.
78
+ It displays an animated fractal based on the the Julia Set. Use the slider
79
+ to tune different parameters."""
80
+ )
81
+
82
+ animation_demo()
83
+
84
+ show_code(animation_demo)
hello/pages/1_Plotting_Demo.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import time
16
+
17
+ import numpy as np
18
+
19
+ import streamlit as st
20
+ from streamlit.hello.utils import show_code
21
+
22
+
23
+ def plotting_demo():
24
+ progress_bar = st.sidebar.progress(0)
25
+ status_text = st.sidebar.empty()
26
+ last_rows = np.random.randn(1, 1)
27
+ chart = st.line_chart(last_rows)
28
+
29
+ for i in range(1, 101):
30
+ new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)
31
+ status_text.text("%i%% Complete" % i)
32
+ chart.add_rows(new_rows)
33
+ progress_bar.progress(i)
34
+ last_rows = new_rows
35
+ time.sleep(0.05)
36
+
37
+ progress_bar.empty()
38
+
39
+ # Streamlit widgets automatically run the script from top to bottom. Since
40
+ # this button is not connected to any other logic, it just causes a plain
41
+ # rerun.
42
+ st.button("Re-run")
43
+
44
+
45
+ st.set_page_config(page_title="Plotting Demo", page_icon="πŸ“ˆ")
46
+ st.markdown("# Plotting Demo")
47
+ st.sidebar.header("Plotting Demo")
48
+ st.write(
49
+ """This demo illustrates a combination of plotting and animation with
50
+ Streamlit. We're generating a bunch of random numbers in a loop for around
51
+ 5 seconds. Enjoy!"""
52
+ )
53
+
54
+ plotting_demo()
55
+
56
+ show_code(plotting_demo)
hello/pages/2_Mapping_Demo.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from urllib.error import URLError
16
+
17
+ import pandas as pd
18
+ import pydeck as pdk
19
+
20
+ import streamlit as st
21
+ from streamlit.hello.utils import show_code
22
+
23
+
24
+ def mapping_demo():
25
+ @st.cache
26
+ def from_data_file(filename):
27
+ url = (
28
+ "http://raw.githubusercontent.com/streamlit/"
29
+ "example-data/master/hello/v1/%s" % filename
30
+ )
31
+ return pd.read_json(url)
32
+
33
+ try:
34
+ ALL_LAYERS = {
35
+ "Bike Rentals": pdk.Layer(
36
+ "HexagonLayer",
37
+ data=from_data_file("bike_rental_stats.json"),
38
+ get_position=["lon", "lat"],
39
+ radius=200,
40
+ elevation_scale=4,
41
+ elevation_range=[0, 1000],
42
+ extruded=True,
43
+ ),
44
+ "Bart Stop Exits": pdk.Layer(
45
+ "ScatterplotLayer",
46
+ data=from_data_file("bart_stop_stats.json"),
47
+ get_position=["lon", "lat"],
48
+ get_color=[200, 30, 0, 160],
49
+ get_radius="[exits]",
50
+ radius_scale=0.05,
51
+ ),
52
+ "Bart Stop Names": pdk.Layer(
53
+ "TextLayer",
54
+ data=from_data_file("bart_stop_stats.json"),
55
+ get_position=["lon", "lat"],
56
+ get_text="name",
57
+ get_color=[0, 0, 0, 200],
58
+ get_size=15,
59
+ get_alignment_baseline="'bottom'",
60
+ ),
61
+ "Outbound Flow": pdk.Layer(
62
+ "ArcLayer",
63
+ data=from_data_file("bart_path_stats.json"),
64
+ get_source_position=["lon", "lat"],
65
+ get_target_position=["lon2", "lat2"],
66
+ get_source_color=[200, 30, 0, 160],
67
+ get_target_color=[200, 30, 0, 160],
68
+ auto_highlight=True,
69
+ width_scale=0.0001,
70
+ get_width="outbound",
71
+ width_min_pixels=3,
72
+ width_max_pixels=30,
73
+ ),
74
+ }
75
+ st.sidebar.markdown("### Map Layers")
76
+ selected_layers = [
77
+ layer
78
+ for layer_name, layer in ALL_LAYERS.items()
79
+ if st.sidebar.checkbox(layer_name, True)
80
+ ]
81
+ if selected_layers:
82
+ st.pydeck_chart(
83
+ pdk.Deck(
84
+ map_style=None,
85
+ initial_view_state={
86
+ "latitude": 37.76,
87
+ "longitude": -122.4,
88
+ "zoom": 11,
89
+ "pitch": 50,
90
+ },
91
+ layers=selected_layers,
92
+ )
93
+ )
94
+ else:
95
+ st.error("Please choose at least one layer above.")
96
+ except URLError as e:
97
+ st.error(
98
+ """
99
+ **This demo requires internet access.**
100
+ Connection error: %s
101
+ """
102
+ % e.reason
103
+ )
104
+
105
+
106
+ st.set_page_config(page_title="Mapping Demo", page_icon="🌍")
107
+ st.markdown("# Mapping Demo")
108
+ st.sidebar.header("Mapping Demo")
109
+ st.write(
110
+ """This demo shows how to use
111
+ [`st.pydeck_chart`](https://docs.streamlit.io/library/api-reference/charts/st.pydeck_chart)
112
+ to display geospatial data."""
113
+ )
114
+
115
+ mapping_demo()
116
+
117
+ show_code(mapping_demo)
hello/pages/3_DataFrame_Demo.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from urllib.error import URLError
16
+
17
+ import altair as alt
18
+ import pandas as pd
19
+
20
+ import streamlit as st
21
+ from streamlit.hello.utils import show_code
22
+
23
+
24
+ def data_frame_demo():
25
+ @st.cache
26
+ def get_UN_data():
27
+ AWS_BUCKET_URL = "http://streamlit-demo-data.s3-us-west-2.amazonaws.com"
28
+ df = pd.read_csv(AWS_BUCKET_URL + "/agri.csv.gz")
29
+ return df.set_index("Region")
30
+
31
+ try:
32
+ df = get_UN_data()
33
+ countries = st.multiselect(
34
+ "Choose countries", list(df.index), ["China", "United States of America"]
35
+ )
36
+ if not countries:
37
+ st.error("Please select at least one country.")
38
+ else:
39
+ data = df.loc[countries]
40
+ data /= 1000000.0
41
+ st.write("### Gross Agricultural Production ($B)", data.sort_index())
42
+
43
+ data = data.T.reset_index()
44
+ data = pd.melt(data, id_vars=["index"]).rename(
45
+ columns={"index": "year", "value": "Gross Agricultural Product ($B)"}
46
+ )
47
+ chart = (
48
+ alt.Chart(data)
49
+ .mark_area(opacity=0.3)
50
+ .encode(
51
+ x="year:T",
52
+ y=alt.Y("Gross Agricultural Product ($B):Q", stack=None),
53
+ color="Region:N",
54
+ )
55
+ )
56
+ st.altair_chart(chart, use_container_width=True)
57
+ except URLError as e:
58
+ st.error(
59
+ """
60
+ **This demo requires internet access.**
61
+ Connection error: %s
62
+ """
63
+ % e.reason
64
+ )
65
+
66
+
67
+ st.set_page_config(page_title="DataFrame Demo", page_icon="πŸ“Š")
68
+ st.markdown("# DataFrame Demo")
69
+ st.sidebar.header("DataFrame Demo")
70
+ st.write(
71
+ """This demo shows how to use `st.write` to visualize Pandas DataFrames.
72
+ (Data courtesy of the [UN Data Explorer](http://data.un.org/Explorer.aspx).)"""
73
+ )
74
+
75
+ data_frame_demo()
76
+
77
+ show_code(data_frame_demo)
hello/utils.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import inspect
16
+ import textwrap
17
+
18
+ import streamlit as st
19
+
20
+
21
+ def show_code(demo):
22
+ """Showing the code of the demo."""
23
+ show_code = st.sidebar.checkbox("Show code", True)
24
+ if show_code:
25
+ # Showing the code of the demo.
26
+ st.markdown("## Code")
27
+ sourcelines, _ = inspect.getsourcelines(demo)
28
+ st.code(textwrap.dedent("".join(sourcelines[1:])))