We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unnecessary space symbol in markdown in lib/streamlit/hello/demos.py 
### Summary
There are unnecessary space symbols in markdown in lib/streamlit/hello/demos.py 

### Steps to reproduce

Code snippet (https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/hello/demos.py):

```
    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)
    """
    )
```
If applicable, please provide the steps we should take to reproduce the bug:

1. run "streamlit hello"
2. open the front page
3. pay attention to the "See more complex demos" section

**Actual behavior:**
Markdown links are broken. There should not be spaces between `[text]` and `(URL)` parts (see code snippet)
![image](https://user-images.githubusercontent.com/23180059/155370113-e0311ba8-1968-4401-96b8-d527a3172e3b.png)

**Expected behavior:**
Links are correctly shown

### Is this a regression?
maybe, but it reproduces in a previous released version

### Debug info

- Streamlit version: 1.6.0rc
- Python version: 3.9.7
- Using Conda and PipEnv


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

{"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@@ -39,9 +39,8 @@\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+          Dataset](https://github.com/streamlit/demo-self-driving)\n+        - Explore a [New York City rideshare dataset](https://github.com/streamlit/demo-uber-nyc-pickups)\n     \"\"\"\n     )\n", "issue": "Unnecessary space symbol in markdown in lib/streamlit/hello/demos.py \n### Summary\r\nThere are unnecessary space symbols in markdown in lib/streamlit/hello/demos.py \r\n\r\n### Steps to reproduce\r\n\r\nCode snippet (https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/hello/demos.py):\r\n\r\n```\r\n    st.markdown(\r\n        \"\"\"\r\n        Streamlit is an open-source app framework built specifically for\r\n        Machine Learning and Data Science projects.\r\n        **\ud83d\udc48 Select a demo from the dropdown on the left** to see some examples\r\n        of what Streamlit can do!\r\n        ### Want to learn more?\r\n        - Check out [streamlit.io](https://streamlit.io)\r\n        - Jump into our [documentation](https://docs.streamlit.io)\r\n        - Ask a question in our [community\r\n          forums](https://discuss.streamlit.io)\r\n        ### See more complex demos\r\n        - Use a neural net to [analyze the Udacity Self-driving Car Image\r\n          Dataset] (https://github.com/streamlit/demo-self-driving)\r\n        - Explore a [New York City rideshare dataset]\r\n          (https://github.com/streamlit/demo-uber-nyc-pickups)\r\n    \"\"\"\r\n    )\r\n```\r\nIf applicable, please provide the steps we should take to reproduce the bug:\r\n\r\n1. run \"streamlit hello\"\r\n2. open the front page\r\n3. pay attention to the \"See more complex demos\" section\r\n\r\n**Actual behavior:**\r\nMarkdown links are broken. There should not be spaces between `[text]` and `(URL)` parts (see code snippet)\r\n![image](https://user-images.githubusercontent.com/23180059/155370113-e0311ba8-1968-4401-96b8-d527a3172e3b.png)\r\n\r\n**Expected behavior:**\r\nLinks are correctly shown\r\n\r\n### Is this a regression?\r\nmaybe, but it reproduces in a previous released version\r\n\r\n### Debug info\r\n\r\n- Streamlit version: 1.6.0rc\r\n- Python version: 3.9.7\r\n- Using Conda and PipEnv\r\n\n", "before_files": [{"content": "# Copyright 2018-2022 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\nfrom typing import Any\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            \"http://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: Any = 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 = \"http://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"}], "after_files": [{"content": "# Copyright 2018-2022 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\nfrom typing import Any\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](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            \"http://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: Any = 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 = \"http://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"}]}