We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Missing "import urllib" in "streamlit hello" mapping/dataframe demo code
The mapping and dataframe demo (`streamlit hello`, select mapping option on left hand size, have "show code" checked) seems to be missing "import urllib" in the code section below the live demo;

The code uses `except urllib.error.URLError as e:` but urllib is never imported; copying and pasting the code into an app does show the import error.

Tested on streamlit 0.78.0, python 3.8.

EDIT 1: make it clearer
EDIT 2: Just realized the same thing happens for the Dataframe demo, edited.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/streamlit/hello/demos.py`
Content:
```
1 # Copyright 2018-2021 Streamlit Inc.
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 urllib.error
16 
17 
18 def intro():
19     import streamlit as st
20 
21     st.sidebar.success("Select a demo above.")
22 
23     st.markdown(
24         """
25         Streamlit is an open-source app framework built specifically for
26         Machine Learning and Data Science projects.
27 
28         **👈 Select a demo from the dropdown on the left** to see some examples
29         of what Streamlit can do!
30 
31         ### Want to learn more?
32 
33         - Check out [streamlit.io](https://streamlit.io)
34         - Jump into our [documentation](https://docs.streamlit.io)
35         - Ask a question in our [community
36           forums](https://discuss.streamlit.io)
37 
38         ### See more complex demos
39 
40         - Use a neural net to [analyze the Udacity Self-driving Car Image
41           Dataset] (https://github.com/streamlit/demo-self-driving)
42         - Explore a [New York City rideshare dataset]
43           (https://github.com/streamlit/demo-uber-nyc-pickups)
44     """
45     )
46 
47 
48 # Turn off black formatting for this function to present the user with more
49 # compact code.
50 # fmt: off
51 def mapping_demo():
52     import streamlit as st
53     import pandas as pd
54     import pydeck as pdk
55 
56     @st.cache
57     def from_data_file(filename):
58         url = (
59             "https://raw.githubusercontent.com/streamlit/"
60             "example-data/master/hello/v1/%s" % filename)
61         return pd.read_json(url)
62 
63     try:
64         ALL_LAYERS = {
65             "Bike Rentals": pdk.Layer(
66                 "HexagonLayer",
67                 data=from_data_file("bike_rental_stats.json"),
68                 get_position=["lon", "lat"],
69                 radius=200,
70                 elevation_scale=4,
71                 elevation_range=[0, 1000],
72                 extruded=True,
73             ),
74             "Bart Stop Exits": pdk.Layer(
75                 "ScatterplotLayer",
76                 data=from_data_file("bart_stop_stats.json"),
77                 get_position=["lon", "lat"],
78                 get_color=[200, 30, 0, 160],
79                 get_radius="[exits]",
80                 radius_scale=0.05,
81             ),
82             "Bart Stop Names": pdk.Layer(
83                 "TextLayer",
84                 data=from_data_file("bart_stop_stats.json"),
85                 get_position=["lon", "lat"],
86                 get_text="name",
87                 get_color=[0, 0, 0, 200],
88                 get_size=15,
89                 get_alignment_baseline="'bottom'",
90             ),
91             "Outbound Flow": pdk.Layer(
92                 "ArcLayer",
93                 data=from_data_file("bart_path_stats.json"),
94                 get_source_position=["lon", "lat"],
95                 get_target_position=["lon2", "lat2"],
96                 get_source_color=[200, 30, 0, 160],
97                 get_target_color=[200, 30, 0, 160],
98                 auto_highlight=True,
99                 width_scale=0.0001,
100                 get_width="outbound",
101                 width_min_pixels=3,
102                 width_max_pixels=30,
103             ),
104         }
105         st.sidebar.markdown('### Map Layers')
106         selected_layers = [
107             layer for layer_name, layer in ALL_LAYERS.items()
108             if st.sidebar.checkbox(layer_name, True)]
109         if selected_layers:
110             st.pydeck_chart(pdk.Deck(
111                 map_style="mapbox://styles/mapbox/light-v9",
112                 initial_view_state={"latitude": 37.76,
113                                     "longitude": -122.4, "zoom": 11, "pitch": 50},
114                 layers=selected_layers,
115             ))
116         else:
117             st.error("Please choose at least one layer above.")
118     except urllib.error.URLError as e:
119         st.error("""
120             **This demo requires internet access.**
121 
122             Connection error: %s
123         """ % e.reason)
124 # fmt: on
125 
126 # Turn off black formatting for this function to present the user with more
127 # compact code.
128 # fmt: off
129 
130 
131 def fractal_demo():
132     import streamlit as st
133     import numpy as np
134 
135     # Interactive Streamlit elements, like these sliders, return their value.
136     # This gives you an extremely simple interaction model.
137     iterations = st.sidebar.slider("Level of detail", 2, 20, 10, 1)
138     separation = st.sidebar.slider("Separation", 0.7, 2.0, 0.7885)
139 
140     # Non-interactive elements return a placeholder to their location
141     # in the app. Here we're storing progress_bar to update it later.
142     progress_bar = st.sidebar.progress(0)
143 
144     # These two elements will be filled in later, so we create a placeholder
145     # for them using st.empty()
146     frame_text = st.sidebar.empty()
147     image = st.empty()
148 
149     m, n, s = 960, 640, 400
150     x = np.linspace(-m / s, m / s, num=m).reshape((1, m))
151     y = np.linspace(-n / s, n / s, num=n).reshape((n, 1))
152 
153     for frame_num, a in enumerate(np.linspace(0.0, 4 * np.pi, 100)):
154         # Here were setting value for these two elements.
155         progress_bar.progress(frame_num)
156         frame_text.text("Frame %i/100" % (frame_num + 1))
157 
158         # Performing some fractal wizardry.
159         c = separation * np.exp(1j * a)
160         Z = np.tile(x, (n, 1)) + 1j * np.tile(y, (1, m))
161         C = np.full((n, m), c)
162         M = np.full((n, m), True, dtype=bool)
163         N = np.zeros((n, m))
164 
165         for i in range(iterations):
166             Z[M] = Z[M] * Z[M] + C[M]
167             M[np.abs(Z) > 2] = False
168             N[M] = i
169 
170         # Update the image placeholder by calling the image() function on it.
171         image.image(1.0 - (N / N.max()), use_column_width=True)
172 
173     # We clear elements by calling empty on them.
174     progress_bar.empty()
175     frame_text.empty()
176 
177     # Streamlit widgets automatically run the script from top to bottom. Since
178     # this button is not connected to any other logic, it just causes a plain
179     # rerun.
180     st.button("Re-run")
181 
182 
183 # fmt: on
184 
185 # Turn off black formatting for this function to present the user with more
186 # compact code.
187 # fmt: off
188 def plotting_demo():
189     import streamlit as st
190     import time
191     import numpy as np
192 
193     progress_bar = st.sidebar.progress(0)
194     status_text = st.sidebar.empty()
195     last_rows = np.random.randn(1, 1)
196     chart = st.line_chart(last_rows)
197 
198     for i in range(1, 101):
199         new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)
200         status_text.text("%i%% Complete" % i)
201         chart.add_rows(new_rows)
202         progress_bar.progress(i)
203         last_rows = new_rows
204         time.sleep(0.05)
205 
206     progress_bar.empty()
207 
208     # Streamlit widgets automatically run the script from top to bottom. Since
209     # this button is not connected to any other logic, it just causes a plain
210     # rerun.
211     st.button("Re-run")
212 
213 
214 # fmt: on
215 
216 # Turn off black formatting for this function to present the user with more
217 # compact code.
218 # fmt: off
219 def data_frame_demo():
220     import streamlit as st
221     import pandas as pd
222     import altair as alt
223 
224     @st.cache
225     def get_UN_data():
226         AWS_BUCKET_URL = "https://streamlit-demo-data.s3-us-west-2.amazonaws.com"
227         df = pd.read_csv(AWS_BUCKET_URL + "/agri.csv.gz")
228         return df.set_index("Region")
229 
230     try:
231         df = get_UN_data()
232         countries = st.multiselect(
233             "Choose countries", list(df.index), ["China", "United States of America"]
234         )
235         if not countries:
236             st.error("Please select at least one country.")
237         else:
238             data = df.loc[countries]
239             data /= 1000000.0
240             st.write("### Gross Agricultural Production ($B)", data.sort_index())
241 
242             data = data.T.reset_index()
243             data = pd.melt(data, id_vars=["index"]).rename(
244                 columns={"index": "year", "value": "Gross Agricultural Product ($B)"}
245             )
246             chart = (
247                 alt.Chart(data)
248                 .mark_area(opacity=0.3)
249                 .encode(
250                     x="year:T",
251                     y=alt.Y("Gross Agricultural Product ($B):Q", stack=None),
252                     color="Region:N",
253                 )
254             )
255             st.altair_chart(chart, use_container_width=True)
256     except urllib.error.URLError as e:
257         st.error(
258             """
259             **This demo requires internet access.**
260 
261             Connection error: %s
262         """
263             % e.reason
264         )
265 
266 
267 # fmt: on
268
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/streamlit/hello/demos.py b/lib/streamlit/hello/demos.py
--- a/lib/streamlit/hello/demos.py
+++ b/lib/streamlit/hello/demos.py
@@ -12,8 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import urllib.error
-
 
 def intro():
     import streamlit as st
@@ -53,6 +51,8 @@
     import pandas as pd
     import pydeck as pdk
 
+    from urllib.error import URLError
+
     @st.cache
     def from_data_file(filename):
         url = (
@@ -115,7 +115,7 @@
             ))
         else:
             st.error("Please choose at least one layer above.")
-    except urllib.error.URLError as e:
+    except URLError as e:
         st.error("""
             **This demo requires internet access.**
 
@@ -221,6 +221,8 @@
     import pandas as pd
     import altair as alt
 
+    from urllib.error import URLError
+
     @st.cache
     def get_UN_data():
         AWS_BUCKET_URL = "https://streamlit-demo-data.s3-us-west-2.amazonaws.com"
@@ -253,7 +255,7 @@
                 )
             )
             st.altair_chart(chart, use_container_width=True)
-    except urllib.error.URLError as e:
+    except URLError as e:
         st.error(
             """
             **This demo requires internet access.**

{"golden_diff": "diff --git a/lib/streamlit/hello/demos.py b/lib/streamlit/hello/demos.py\n--- a/lib/streamlit/hello/demos.py\n+++ b/lib/streamlit/hello/demos.py\n@@ -12,8 +12,6 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \n-import urllib.error\n-\n \n def intro():\n     import streamlit as st\n@@ -53,6 +51,8 @@\n     import pandas as pd\n     import pydeck as pdk\n \n+    from urllib.error import URLError\n+\n     @st.cache\n     def from_data_file(filename):\n         url = (\n@@ -115,7 +115,7 @@\n             ))\n         else:\n             st.error(\"Please choose at least one layer above.\")\n-    except urllib.error.URLError as e:\n+    except URLError as e:\n         st.error(\"\"\"\n             **This demo requires internet access.**\n \n@@ -221,6 +221,8 @@\n     import pandas as pd\n     import altair as alt\n \n+    from urllib.error import URLError\n+\n     @st.cache\n     def get_UN_data():\n         AWS_BUCKET_URL = \"https://streamlit-demo-data.s3-us-west-2.amazonaws.com\"\n@@ -253,7 +255,7 @@\n                 )\n             )\n             st.altair_chart(chart, use_container_width=True)\n-    except urllib.error.URLError as e:\n+    except URLError as e:\n         st.error(\n             \"\"\"\n             **This demo requires internet access.**\n", "issue": "Missing \"import urllib\" in \"streamlit hello\" mapping/dataframe demo code\nThe mapping and dataframe demo (`streamlit hello`, select mapping option on left hand size, have \"show code\" checked) seems to be missing \"import urllib\" in the code section below the live demo;\r\n\r\nThe code uses `except urllib.error.URLError as e:` but urllib is never imported; copying and pasting the code into an app does show the import error.\r\n\r\nTested on streamlit 0.78.0, python 3.8.\r\n\r\nEDIT 1: make it clearer\r\nEDIT 2: Just realized the same thing happens for the Dataframe demo, edited.\n", "before_files": [{"content": "# Copyright 2018-2021 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport urllib.error\n\n\ndef intro():\n    import streamlit as st\n\n    st.sidebar.success(\"Select a demo above.\")\n\n    st.markdown(\n        \"\"\"\n        Streamlit is an open-source app framework built specifically for\n        Machine Learning and Data Science projects.\n\n        **\ud83d\udc48 Select a demo from the dropdown on the left** to see some examples\n        of what Streamlit can do!\n\n        ### Want to learn more?\n\n        - Check out [streamlit.io](https://streamlit.io)\n        - Jump into our [documentation](https://docs.streamlit.io)\n        - Ask a question in our [community\n          forums](https://discuss.streamlit.io)\n\n        ### See more complex demos\n\n        - Use a neural net to [analyze the Udacity Self-driving Car Image\n          Dataset] (https://github.com/streamlit/demo-self-driving)\n        - Explore a [New York City rideshare dataset]\n          (https://github.com/streamlit/demo-uber-nyc-pickups)\n    \"\"\"\n    )\n\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\ndef mapping_demo():\n    import streamlit as st\n    import pandas as pd\n    import pydeck as pdk\n\n    @st.cache\n    def from_data_file(filename):\n        url = (\n            \"https://raw.githubusercontent.com/streamlit/\"\n            \"example-data/master/hello/v1/%s\" % filename)\n        return pd.read_json(url)\n\n    try:\n        ALL_LAYERS = {\n            \"Bike Rentals\": pdk.Layer(\n                \"HexagonLayer\",\n                data=from_data_file(\"bike_rental_stats.json\"),\n                get_position=[\"lon\", \"lat\"],\n                radius=200,\n                elevation_scale=4,\n                elevation_range=[0, 1000],\n                extruded=True,\n            ),\n            \"Bart Stop Exits\": pdk.Layer(\n                \"ScatterplotLayer\",\n                data=from_data_file(\"bart_stop_stats.json\"),\n                get_position=[\"lon\", \"lat\"],\n                get_color=[200, 30, 0, 160],\n                get_radius=\"[exits]\",\n                radius_scale=0.05,\n            ),\n            \"Bart Stop Names\": pdk.Layer(\n                \"TextLayer\",\n                data=from_data_file(\"bart_stop_stats.json\"),\n                get_position=[\"lon\", \"lat\"],\n                get_text=\"name\",\n                get_color=[0, 0, 0, 200],\n                get_size=15,\n                get_alignment_baseline=\"'bottom'\",\n            ),\n            \"Outbound Flow\": pdk.Layer(\n                \"ArcLayer\",\n                data=from_data_file(\"bart_path_stats.json\"),\n                get_source_position=[\"lon\", \"lat\"],\n                get_target_position=[\"lon2\", \"lat2\"],\n                get_source_color=[200, 30, 0, 160],\n                get_target_color=[200, 30, 0, 160],\n                auto_highlight=True,\n                width_scale=0.0001,\n                get_width=\"outbound\",\n                width_min_pixels=3,\n                width_max_pixels=30,\n            ),\n        }\n        st.sidebar.markdown('### Map Layers')\n        selected_layers = [\n            layer for layer_name, layer in ALL_LAYERS.items()\n            if st.sidebar.checkbox(layer_name, True)]\n        if selected_layers:\n            st.pydeck_chart(pdk.Deck(\n                map_style=\"mapbox://styles/mapbox/light-v9\",\n                initial_view_state={\"latitude\": 37.76,\n                                    \"longitude\": -122.4, \"zoom\": 11, \"pitch\": 50},\n                layers=selected_layers,\n            ))\n        else:\n            st.error(\"Please choose at least one layer above.\")\n    except urllib.error.URLError as e:\n        st.error(\"\"\"\n            **This demo requires internet access.**\n\n            Connection error: %s\n        \"\"\" % e.reason)\n# fmt: on\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\n\n\ndef fractal_demo():\n    import streamlit as st\n    import numpy as np\n\n    # Interactive Streamlit elements, like these sliders, return their value.\n    # This gives you an extremely simple interaction model.\n    iterations = st.sidebar.slider(\"Level of detail\", 2, 20, 10, 1)\n    separation = st.sidebar.slider(\"Separation\", 0.7, 2.0, 0.7885)\n\n    # Non-interactive elements return a placeholder to their location\n    # in the app. Here we're storing progress_bar to update it later.\n    progress_bar = st.sidebar.progress(0)\n\n    # These two elements will be filled in later, so we create a placeholder\n    # for them using st.empty()\n    frame_text = st.sidebar.empty()\n    image = st.empty()\n\n    m, n, s = 960, 640, 400\n    x = np.linspace(-m / s, m / s, num=m).reshape((1, m))\n    y = np.linspace(-n / s, n / s, num=n).reshape((n, 1))\n\n    for frame_num, a in enumerate(np.linspace(0.0, 4 * np.pi, 100)):\n        # Here were setting value for these two elements.\n        progress_bar.progress(frame_num)\n        frame_text.text(\"Frame %i/100\" % (frame_num + 1))\n\n        # Performing some fractal wizardry.\n        c = separation * np.exp(1j * a)\n        Z = np.tile(x, (n, 1)) + 1j * np.tile(y, (1, m))\n        C = np.full((n, m), c)\n        M = np.full((n, m), True, dtype=bool)\n        N = np.zeros((n, m))\n\n        for i in range(iterations):\n            Z[M] = Z[M] * Z[M] + C[M]\n            M[np.abs(Z) > 2] = False\n            N[M] = i\n\n        # Update the image placeholder by calling the image() function on it.\n        image.image(1.0 - (N / N.max()), use_column_width=True)\n\n    # We clear elements by calling empty on them.\n    progress_bar.empty()\n    frame_text.empty()\n\n    # Streamlit widgets automatically run the script from top to bottom. Since\n    # this button is not connected to any other logic, it just causes a plain\n    # rerun.\n    st.button(\"Re-run\")\n\n\n# fmt: on\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\ndef plotting_demo():\n    import streamlit as st\n    import time\n    import numpy as np\n\n    progress_bar = st.sidebar.progress(0)\n    status_text = st.sidebar.empty()\n    last_rows = np.random.randn(1, 1)\n    chart = st.line_chart(last_rows)\n\n    for i in range(1, 101):\n        new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)\n        status_text.text(\"%i%% Complete\" % i)\n        chart.add_rows(new_rows)\n        progress_bar.progress(i)\n        last_rows = new_rows\n        time.sleep(0.05)\n\n    progress_bar.empty()\n\n    # Streamlit widgets automatically run the script from top to bottom. Since\n    # this button is not connected to any other logic, it just causes a plain\n    # rerun.\n    st.button(\"Re-run\")\n\n\n# fmt: on\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\ndef data_frame_demo():\n    import streamlit as st\n    import pandas as pd\n    import altair as alt\n\n    @st.cache\n    def get_UN_data():\n        AWS_BUCKET_URL = \"https://streamlit-demo-data.s3-us-west-2.amazonaws.com\"\n        df = pd.read_csv(AWS_BUCKET_URL + \"/agri.csv.gz\")\n        return df.set_index(\"Region\")\n\n    try:\n        df = get_UN_data()\n        countries = st.multiselect(\n            \"Choose countries\", list(df.index), [\"China\", \"United States of America\"]\n        )\n        if not countries:\n            st.error(\"Please select at least one country.\")\n        else:\n            data = df.loc[countries]\n            data /= 1000000.0\n            st.write(\"### Gross Agricultural Production ($B)\", data.sort_index())\n\n            data = data.T.reset_index()\n            data = pd.melt(data, id_vars=[\"index\"]).rename(\n                columns={\"index\": \"year\", \"value\": \"Gross Agricultural Product ($B)\"}\n            )\n            chart = (\n                alt.Chart(data)\n                .mark_area(opacity=0.3)\n                .encode(\n                    x=\"year:T\",\n                    y=alt.Y(\"Gross Agricultural Product ($B):Q\", stack=None),\n                    color=\"Region:N\",\n                )\n            )\n            st.altair_chart(chart, use_container_width=True)\n    except urllib.error.URLError as e:\n        st.error(\n            \"\"\"\n            **This demo requires internet access.**\n\n            Connection error: %s\n        \"\"\"\n            % e.reason\n        )\n\n\n# fmt: on\n", "path": "lib/streamlit/hello/demos.py"}], "after_files": [{"content": "# Copyright 2018-2021 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\ndef intro():\n    import streamlit as st\n\n    st.sidebar.success(\"Select a demo above.\")\n\n    st.markdown(\n        \"\"\"\n        Streamlit is an open-source app framework built specifically for\n        Machine Learning and Data Science projects.\n\n        **\ud83d\udc48 Select a demo from the dropdown on the left** to see some examples\n        of what Streamlit can do!\n\n        ### Want to learn more?\n\n        - Check out [streamlit.io](https://streamlit.io)\n        - Jump into our [documentation](https://docs.streamlit.io)\n        - Ask a question in our [community\n          forums](https://discuss.streamlit.io)\n\n        ### See more complex demos\n\n        - Use a neural net to [analyze the Udacity Self-driving Car Image\n          Dataset] (https://github.com/streamlit/demo-self-driving)\n        - Explore a [New York City rideshare dataset]\n          (https://github.com/streamlit/demo-uber-nyc-pickups)\n    \"\"\"\n    )\n\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\ndef mapping_demo():\n    import streamlit as st\n    import pandas as pd\n    import pydeck as pdk\n\n    from urllib.error import URLError\n\n    @st.cache\n    def from_data_file(filename):\n        url = (\n            \"https://raw.githubusercontent.com/streamlit/\"\n            \"example-data/master/hello/v1/%s\" % filename)\n        return pd.read_json(url)\n\n    try:\n        ALL_LAYERS = {\n            \"Bike Rentals\": pdk.Layer(\n                \"HexagonLayer\",\n                data=from_data_file(\"bike_rental_stats.json\"),\n                get_position=[\"lon\", \"lat\"],\n                radius=200,\n                elevation_scale=4,\n                elevation_range=[0, 1000],\n                extruded=True,\n            ),\n            \"Bart Stop Exits\": pdk.Layer(\n                \"ScatterplotLayer\",\n                data=from_data_file(\"bart_stop_stats.json\"),\n                get_position=[\"lon\", \"lat\"],\n                get_color=[200, 30, 0, 160],\n                get_radius=\"[exits]\",\n                radius_scale=0.05,\n            ),\n            \"Bart Stop Names\": pdk.Layer(\n                \"TextLayer\",\n                data=from_data_file(\"bart_stop_stats.json\"),\n                get_position=[\"lon\", \"lat\"],\n                get_text=\"name\",\n                get_color=[0, 0, 0, 200],\n                get_size=15,\n                get_alignment_baseline=\"'bottom'\",\n            ),\n            \"Outbound Flow\": pdk.Layer(\n                \"ArcLayer\",\n                data=from_data_file(\"bart_path_stats.json\"),\n                get_source_position=[\"lon\", \"lat\"],\n                get_target_position=[\"lon2\", \"lat2\"],\n                get_source_color=[200, 30, 0, 160],\n                get_target_color=[200, 30, 0, 160],\n                auto_highlight=True,\n                width_scale=0.0001,\n                get_width=\"outbound\",\n                width_min_pixels=3,\n                width_max_pixels=30,\n            ),\n        }\n        st.sidebar.markdown('### Map Layers')\n        selected_layers = [\n            layer for layer_name, layer in ALL_LAYERS.items()\n            if st.sidebar.checkbox(layer_name, True)]\n        if selected_layers:\n            st.pydeck_chart(pdk.Deck(\n                map_style=\"mapbox://styles/mapbox/light-v9\",\n                initial_view_state={\"latitude\": 37.76,\n                                    \"longitude\": -122.4, \"zoom\": 11, \"pitch\": 50},\n                layers=selected_layers,\n            ))\n        else:\n            st.error(\"Please choose at least one layer above.\")\n    except URLError as e:\n        st.error(\"\"\"\n            **This demo requires internet access.**\n\n            Connection error: %s\n        \"\"\" % e.reason)\n# fmt: on\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\n\n\ndef fractal_demo():\n    import streamlit as st\n    import numpy as np\n\n    # Interactive Streamlit elements, like these sliders, return their value.\n    # This gives you an extremely simple interaction model.\n    iterations = st.sidebar.slider(\"Level of detail\", 2, 20, 10, 1)\n    separation = st.sidebar.slider(\"Separation\", 0.7, 2.0, 0.7885)\n\n    # Non-interactive elements return a placeholder to their location\n    # in the app. Here we're storing progress_bar to update it later.\n    progress_bar = st.sidebar.progress(0)\n\n    # These two elements will be filled in later, so we create a placeholder\n    # for them using st.empty()\n    frame_text = st.sidebar.empty()\n    image = st.empty()\n\n    m, n, s = 960, 640, 400\n    x = np.linspace(-m / s, m / s, num=m).reshape((1, m))\n    y = np.linspace(-n / s, n / s, num=n).reshape((n, 1))\n\n    for frame_num, a in enumerate(np.linspace(0.0, 4 * np.pi, 100)):\n        # Here were setting value for these two elements.\n        progress_bar.progress(frame_num)\n        frame_text.text(\"Frame %i/100\" % (frame_num + 1))\n\n        # Performing some fractal wizardry.\n        c = separation * np.exp(1j * a)\n        Z = np.tile(x, (n, 1)) + 1j * np.tile(y, (1, m))\n        C = np.full((n, m), c)\n        M = np.full((n, m), True, dtype=bool)\n        N = np.zeros((n, m))\n\n        for i in range(iterations):\n            Z[M] = Z[M] * Z[M] + C[M]\n            M[np.abs(Z) > 2] = False\n            N[M] = i\n\n        # Update the image placeholder by calling the image() function on it.\n        image.image(1.0 - (N / N.max()), use_column_width=True)\n\n    # We clear elements by calling empty on them.\n    progress_bar.empty()\n    frame_text.empty()\n\n    # Streamlit widgets automatically run the script from top to bottom. Since\n    # this button is not connected to any other logic, it just causes a plain\n    # rerun.\n    st.button(\"Re-run\")\n\n\n# fmt: on\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\ndef plotting_demo():\n    import streamlit as st\n    import time\n    import numpy as np\n\n    progress_bar = st.sidebar.progress(0)\n    status_text = st.sidebar.empty()\n    last_rows = np.random.randn(1, 1)\n    chart = st.line_chart(last_rows)\n\n    for i in range(1, 101):\n        new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)\n        status_text.text(\"%i%% Complete\" % i)\n        chart.add_rows(new_rows)\n        progress_bar.progress(i)\n        last_rows = new_rows\n        time.sleep(0.05)\n\n    progress_bar.empty()\n\n    # Streamlit widgets automatically run the script from top to bottom. Since\n    # this button is not connected to any other logic, it just causes a plain\n    # rerun.\n    st.button(\"Re-run\")\n\n\n# fmt: on\n\n# Turn off black formatting for this function to present the user with more\n# compact code.\n# fmt: off\ndef data_frame_demo():\n    import streamlit as st\n    import pandas as pd\n    import altair as alt\n\n    from urllib.error import URLError\n\n    @st.cache\n    def get_UN_data():\n        AWS_BUCKET_URL = \"https://streamlit-demo-data.s3-us-west-2.amazonaws.com\"\n        df = pd.read_csv(AWS_BUCKET_URL + \"/agri.csv.gz\")\n        return df.set_index(\"Region\")\n\n    try:\n        df = get_UN_data()\n        countries = st.multiselect(\n            \"Choose countries\", list(df.index), [\"China\", \"United States of America\"]\n        )\n        if not countries:\n            st.error(\"Please select at least one country.\")\n        else:\n            data = df.loc[countries]\n            data /= 1000000.0\n            st.write(\"### Gross Agricultural Production ($B)\", data.sort_index())\n\n            data = data.T.reset_index()\n            data = pd.melt(data, id_vars=[\"index\"]).rename(\n                columns={\"index\": \"year\", \"value\": \"Gross Agricultural Product ($B)\"}\n            )\n            chart = (\n                alt.Chart(data)\n                .mark_area(opacity=0.3)\n                .encode(\n                    x=\"year:T\",\n                    y=alt.Y(\"Gross Agricultural Product ($B):Q\", stack=None),\n                    color=\"Region:N\",\n                )\n            )\n            st.altair_chart(chart, use_container_width=True)\n    except URLError as e:\n        st.error(\n            \"\"\"\n            **This demo requires internet access.**\n\n            Connection error: %s\n        \"\"\"\n            % e.reason\n        )\n\n\n# fmt: on\n", "path": "lib/streamlit/hello/demos.py"}]}