We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Plotly privacy page outdated
The explanation on the "sharing" argument of the plotly_chart functions link to outdated content. I haven't checked how streamlit handles the new distinction between chart_studio and offline plotly but I guess the text should be rewritten


**Link to doc page in question (if any):**
[The streamlit.plotly_chart documentation says the following on the **sharing** argument:](https://docs.streamlit.io/api.html?highlight=plotly#streamlit.plotly_chart) 


> **sharing** ({'streamlit', 'private', 'secret', 'public'}) – Use ‘streamlit’ to insert the plot and all its dependencies directly in the Streamlit app, which means it works offline too. This is the default. Use any other sharing mode to send the app to Plotly’s servers, and embed the result into the Streamlit app. See https://plot.ly/python/privacy/ for more. Note that these sharing modes require a Plotly account.

**What you think the docs should say:**

**sharing** ({'streamlit', 'private', 'secret', 'public'}) – Use ‘streamlit’ to insert the plot and all its dependencies directly in the Streamlit app, which means it uses plotly's offline mode. Use any other sharing mode to use Plotly’s chart studio. Nb: Plotly chart studio requires an account.






--- 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/elements/plotly_chart.py`
Content:
```
1 # Copyright 2018-2020 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 """Streamlit support for Plotly charts."""
16 
17 import json
18 import urllib.parse
19 
20 from streamlit import caching
21 from streamlit import type_util
22 
23 from streamlit.logger import get_logger
24 from streamlit.proto.PlotlyChart_pb2 import PlotlyChart as PlotlyChartProto
25 
26 LOGGER = get_logger(__name__)
27 
28 SHARING_MODES = set(
29     [
30         # This means the plot will be sent to the Streamlit app rather than to
31         # Plotly.
32         "streamlit",
33         # The three modes below are for plots that should be hosted in Plotly.
34         # These are the names Plotly uses for them.
35         "private",
36         "public",
37         "secret",
38     ]
39 )
40 
41 
42 class PlotlyMixin:
43     def plotly_chart(
44         dg, figure_or_data, use_container_width=False, sharing="streamlit", **kwargs,
45     ):
46         """Display an interactive Plotly chart.
47 
48         Plotly is a charting library for Python. The arguments to this function
49         closely follow the ones for Plotly's `plot()` function. You can find
50         more about Plotly at https://plot.ly/python.
51 
52         Parameters
53         ----------
54         figure_or_data : plotly.graph_objs.Figure, plotly.graph_objs.Data,
55             dict/list of plotly.graph_objs.Figure/Data
56 
57             See https://plot.ly/python/ for examples of graph descriptions.
58 
59         use_container_width : bool
60             If True, set the chart width to the column width. This takes
61             precedence over the figure's native `width` value.
62 
63         sharing : {'streamlit', 'private', 'secret', 'public'}
64             Use 'streamlit' to insert the plot and all its dependencies
65             directly in the Streamlit app, which means it works offline too.
66             This is the default.
67             Use any other sharing mode to send the app to Plotly's servers,
68             and embed the result into the Streamlit app. See
69             https://plot.ly/python/privacy/ for more. Note that these sharing
70             modes require a Plotly account.
71 
72         **kwargs
73             Any argument accepted by Plotly's `plot()` function.
74 
75 
76         To show Plotly charts in Streamlit, call `st.plotly_chart`
77         wherever you would call Plotly's `py.plot` or `py.iplot`.
78 
79         Example
80         -------
81 
82         The example below comes straight from the examples at
83         https://plot.ly/python:
84 
85         >>> import streamlit as st
86         >>> import plotly.figure_factory as ff
87         >>> import numpy as np
88         >>>
89         >>> # Add histogram data
90         >>> x1 = np.random.randn(200) - 2
91         >>> x2 = np.random.randn(200)
92         >>> x3 = np.random.randn(200) + 2
93         >>>
94         >>> # Group data together
95         >>> hist_data = [x1, x2, x3]
96         >>>
97         >>> group_labels = ['Group 1', 'Group 2', 'Group 3']
98         >>>
99         >>> # Create distplot with custom bin_size
100         >>> fig = ff.create_distplot(
101         ...         hist_data, group_labels, bin_size=[.1, .25, .5])
102         >>>
103         >>> # Plot!
104         >>> st.plotly_chart(fig, use_container_width=True)
105 
106         .. output::
107            https://static.streamlit.io/0.56.0-xTAd/index.html?id=TuP96xX8JnsoQeUGAPjkGQ
108            height: 400px
109 
110         """
111         # NOTE: "figure_or_data" is the name used in Plotly's .plot() method
112         # for their main parameter. I don't like the name, but it's best to
113         # keep it in sync with what Plotly calls it.
114         import streamlit.elements.plotly_chart as plotly_chart
115 
116         plotly_chart_proto = PlotlyChartProto()
117         marshall(
118             plotly_chart_proto, figure_or_data, use_container_width, sharing, **kwargs
119         )
120         return dg._enqueue("plotly_chart", plotly_chart_proto)  # type: ignore
121 
122 
123 def marshall(proto, figure_or_data, use_container_width, sharing, **kwargs):
124     """Marshall a proto with a Plotly spec.
125 
126     See DeltaGenerator.plotly_chart for docs.
127     """
128     # NOTE: "figure_or_data" is the name used in Plotly's .plot() method
129     # for their main parameter. I don't like the name, but its best to keep
130     # it in sync with what Plotly calls it.
131 
132     import plotly.tools
133 
134     if type_util.is_type(figure_or_data, "matplotlib.figure.Figure"):
135         figure = plotly.tools.mpl_to_plotly(figure_or_data)
136 
137     else:
138         figure = plotly.tools.return_figure_from_figure_or_data(
139             figure_or_data, validate_figure=True
140         )
141 
142     if not isinstance(sharing, str) or sharing.lower() not in SHARING_MODES:
143         raise ValueError("Invalid sharing mode for Plotly chart: %s" % sharing)
144 
145     proto.use_container_width = use_container_width
146 
147     if sharing == "streamlit":
148         import plotly.utils
149 
150         config = dict(kwargs.get("config", {}))
151         # Copy over some kwargs to config dict. Plotly does the same in plot().
152         config.setdefault("showLink", kwargs.get("show_link", False))
153         config.setdefault("linkText", kwargs.get("link_text", False))
154 
155         proto.figure.spec = json.dumps(figure, cls=plotly.utils.PlotlyJSONEncoder)
156         proto.figure.config = json.dumps(config)
157 
158     else:
159         url = _plot_to_url_or_load_cached_url(
160             figure, sharing=sharing, auto_open=False, **kwargs
161         )
162         proto.url = _get_embed_url(url)
163 
164 
165 @caching.cache
166 def _plot_to_url_or_load_cached_url(*args, **kwargs):
167     """Call plotly.plot wrapped in st.cache.
168 
169     This is so we don't unecessarily upload data to Plotly's SASS if nothing
170     changed since the previous upload.
171     """
172     try:
173         # Plotly 4 changed its main package.
174         import chart_studio.plotly as ply
175     except ImportError:
176         import plotly.plotly as ply
177 
178     return ply.plot(*args, **kwargs)
179 
180 
181 def _get_embed_url(url):
182     parsed_url = urllib.parse.urlparse(url)
183 
184     # Plotly's embed URL is the normal URL plus ".embed".
185     # (Note that our use namedtuple._replace is fine because that's not a
186     # private method! It just has an underscore to avoid clashing with the
187     # tuple field names)
188     parsed_embed_url = parsed_url._replace(path=parsed_url.path + ".embed")
189 
190     return urllib.parse.urlunparse(parsed_embed_url)
191
```
--- 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/elements/plotly_chart.py b/lib/streamlit/elements/plotly_chart.py
--- a/lib/streamlit/elements/plotly_chart.py
+++ b/lib/streamlit/elements/plotly_chart.py
@@ -41,7 +41,11 @@
 
 class PlotlyMixin:
     def plotly_chart(
-        dg, figure_or_data, use_container_width=False, sharing="streamlit", **kwargs,
+        dg,
+        figure_or_data,
+        use_container_width=False,
+        sharing="streamlit",
+        **kwargs,
     ):
         """Display an interactive Plotly chart.
 
@@ -62,12 +66,9 @@
 
         sharing : {'streamlit', 'private', 'secret', 'public'}
             Use 'streamlit' to insert the plot and all its dependencies
-            directly in the Streamlit app, which means it works offline too.
-            This is the default.
-            Use any other sharing mode to send the app to Plotly's servers,
-            and embed the result into the Streamlit app. See
-            https://plot.ly/python/privacy/ for more. Note that these sharing
-            modes require a Plotly account.
+            directly in the Streamlit app using plotly's offline mode (default).
+            Use any other sharing mode to send the chart to Plotly chart studio, which
+            requires an account. See https://plotly.com/chart-studio/ for more information.
 
         **kwargs
             Any argument accepted by Plotly's `plot()` function.

{"golden_diff": "diff --git a/lib/streamlit/elements/plotly_chart.py b/lib/streamlit/elements/plotly_chart.py\n--- a/lib/streamlit/elements/plotly_chart.py\n+++ b/lib/streamlit/elements/plotly_chart.py\n@@ -41,7 +41,11 @@\n \n class PlotlyMixin:\n     def plotly_chart(\n-        dg, figure_or_data, use_container_width=False, sharing=\"streamlit\", **kwargs,\n+        dg,\n+        figure_or_data,\n+        use_container_width=False,\n+        sharing=\"streamlit\",\n+        **kwargs,\n     ):\n         \"\"\"Display an interactive Plotly chart.\n \n@@ -62,12 +66,9 @@\n \n         sharing : {'streamlit', 'private', 'secret', 'public'}\n             Use 'streamlit' to insert the plot and all its dependencies\n-            directly in the Streamlit app, which means it works offline too.\n-            This is the default.\n-            Use any other sharing mode to send the app to Plotly's servers,\n-            and embed the result into the Streamlit app. See\n-            https://plot.ly/python/privacy/ for more. Note that these sharing\n-            modes require a Plotly account.\n+            directly in the Streamlit app using plotly's offline mode (default).\n+            Use any other sharing mode to send the chart to Plotly chart studio, which\n+            requires an account. See https://plotly.com/chart-studio/ for more information.\n \n         **kwargs\n             Any argument accepted by Plotly's `plot()` function.\n", "issue": "Plotly privacy page outdated\nThe explanation on the \"sharing\" argument of the plotly_chart functions link to outdated content. I haven't checked how streamlit handles the new distinction between chart_studio and offline plotly but I guess the text should be rewritten\r\n\r\n\r\n**Link to doc page in question (if any):**\r\n[The streamlit.plotly_chart documentation says the following on the **sharing** argument:](https://docs.streamlit.io/api.html?highlight=plotly#streamlit.plotly_chart) \r\n\r\n\r\n> **sharing** ({'streamlit', 'private', 'secret', 'public'}) \u2013 Use \u2018streamlit\u2019 to insert the plot and all its dependencies directly in the Streamlit app, which means it works offline too. This is the default. Use any other sharing mode to send the app to Plotly\u2019s servers, and embed the result into the Streamlit app. See https://plot.ly/python/privacy/ for more. Note that these sharing modes require a Plotly account.\r\n\r\n**What you think the docs should say:**\r\n\r\n**sharing** ({'streamlit', 'private', 'secret', 'public'}) \u2013 Use \u2018streamlit\u2019 to insert the plot and all its dependencies directly in the Streamlit app, which means it uses plotly's offline mode. Use any other sharing mode to use Plotly\u2019s chart studio. Nb: Plotly chart studio requires an account.\r\n\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "# Copyright 2018-2020 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\"\"\"Streamlit support for Plotly charts.\"\"\"\n\nimport json\nimport urllib.parse\n\nfrom streamlit import caching\nfrom streamlit import type_util\n\nfrom streamlit.logger import get_logger\nfrom streamlit.proto.PlotlyChart_pb2 import PlotlyChart as PlotlyChartProto\n\nLOGGER = get_logger(__name__)\n\nSHARING_MODES = set(\n    [\n        # This means the plot will be sent to the Streamlit app rather than to\n        # Plotly.\n        \"streamlit\",\n        # The three modes below are for plots that should be hosted in Plotly.\n        # These are the names Plotly uses for them.\n        \"private\",\n        \"public\",\n        \"secret\",\n    ]\n)\n\n\nclass PlotlyMixin:\n    def plotly_chart(\n        dg, figure_or_data, use_container_width=False, sharing=\"streamlit\", **kwargs,\n    ):\n        \"\"\"Display an interactive Plotly chart.\n\n        Plotly is a charting library for Python. The arguments to this function\n        closely follow the ones for Plotly's `plot()` function. You can find\n        more about Plotly at https://plot.ly/python.\n\n        Parameters\n        ----------\n        figure_or_data : plotly.graph_objs.Figure, plotly.graph_objs.Data,\n            dict/list of plotly.graph_objs.Figure/Data\n\n            See https://plot.ly/python/ for examples of graph descriptions.\n\n        use_container_width : bool\n            If True, set the chart width to the column width. This takes\n            precedence over the figure's native `width` value.\n\n        sharing : {'streamlit', 'private', 'secret', 'public'}\n            Use 'streamlit' to insert the plot and all its dependencies\n            directly in the Streamlit app, which means it works offline too.\n            This is the default.\n            Use any other sharing mode to send the app to Plotly's servers,\n            and embed the result into the Streamlit app. See\n            https://plot.ly/python/privacy/ for more. Note that these sharing\n            modes require a Plotly account.\n\n        **kwargs\n            Any argument accepted by Plotly's `plot()` function.\n\n\n        To show Plotly charts in Streamlit, call `st.plotly_chart`\n        wherever you would call Plotly's `py.plot` or `py.iplot`.\n\n        Example\n        -------\n\n        The example below comes straight from the examples at\n        https://plot.ly/python:\n\n        >>> import streamlit as st\n        >>> import plotly.figure_factory as ff\n        >>> import numpy as np\n        >>>\n        >>> # Add histogram data\n        >>> x1 = np.random.randn(200) - 2\n        >>> x2 = np.random.randn(200)\n        >>> x3 = np.random.randn(200) + 2\n        >>>\n        >>> # Group data together\n        >>> hist_data = [x1, x2, x3]\n        >>>\n        >>> group_labels = ['Group 1', 'Group 2', 'Group 3']\n        >>>\n        >>> # Create distplot with custom bin_size\n        >>> fig = ff.create_distplot(\n        ...         hist_data, group_labels, bin_size=[.1, .25, .5])\n        >>>\n        >>> # Plot!\n        >>> st.plotly_chart(fig, use_container_width=True)\n\n        .. output::\n           https://static.streamlit.io/0.56.0-xTAd/index.html?id=TuP96xX8JnsoQeUGAPjkGQ\n           height: 400px\n\n        \"\"\"\n        # NOTE: \"figure_or_data\" is the name used in Plotly's .plot() method\n        # for their main parameter. I don't like the name, but it's best to\n        # keep it in sync with what Plotly calls it.\n        import streamlit.elements.plotly_chart as plotly_chart\n\n        plotly_chart_proto = PlotlyChartProto()\n        marshall(\n            plotly_chart_proto, figure_or_data, use_container_width, sharing, **kwargs\n        )\n        return dg._enqueue(\"plotly_chart\", plotly_chart_proto)  # type: ignore\n\n\ndef marshall(proto, figure_or_data, use_container_width, sharing, **kwargs):\n    \"\"\"Marshall a proto with a Plotly spec.\n\n    See DeltaGenerator.plotly_chart for docs.\n    \"\"\"\n    # NOTE: \"figure_or_data\" is the name used in Plotly's .plot() method\n    # for their main parameter. I don't like the name, but its best to keep\n    # it in sync with what Plotly calls it.\n\n    import plotly.tools\n\n    if type_util.is_type(figure_or_data, \"matplotlib.figure.Figure\"):\n        figure = plotly.tools.mpl_to_plotly(figure_or_data)\n\n    else:\n        figure = plotly.tools.return_figure_from_figure_or_data(\n            figure_or_data, validate_figure=True\n        )\n\n    if not isinstance(sharing, str) or sharing.lower() not in SHARING_MODES:\n        raise ValueError(\"Invalid sharing mode for Plotly chart: %s\" % sharing)\n\n    proto.use_container_width = use_container_width\n\n    if sharing == \"streamlit\":\n        import plotly.utils\n\n        config = dict(kwargs.get(\"config\", {}))\n        # Copy over some kwargs to config dict. Plotly does the same in plot().\n        config.setdefault(\"showLink\", kwargs.get(\"show_link\", False))\n        config.setdefault(\"linkText\", kwargs.get(\"link_text\", False))\n\n        proto.figure.spec = json.dumps(figure, cls=plotly.utils.PlotlyJSONEncoder)\n        proto.figure.config = json.dumps(config)\n\n    else:\n        url = _plot_to_url_or_load_cached_url(\n            figure, sharing=sharing, auto_open=False, **kwargs\n        )\n        proto.url = _get_embed_url(url)\n\n\n@caching.cache\ndef _plot_to_url_or_load_cached_url(*args, **kwargs):\n    \"\"\"Call plotly.plot wrapped in st.cache.\n\n    This is so we don't unecessarily upload data to Plotly's SASS if nothing\n    changed since the previous upload.\n    \"\"\"\n    try:\n        # Plotly 4 changed its main package.\n        import chart_studio.plotly as ply\n    except ImportError:\n        import plotly.plotly as ply\n\n    return ply.plot(*args, **kwargs)\n\n\ndef _get_embed_url(url):\n    parsed_url = urllib.parse.urlparse(url)\n\n    # Plotly's embed URL is the normal URL plus \".embed\".\n    # (Note that our use namedtuple._replace is fine because that's not a\n    # private method! It just has an underscore to avoid clashing with the\n    # tuple field names)\n    parsed_embed_url = parsed_url._replace(path=parsed_url.path + \".embed\")\n\n    return urllib.parse.urlunparse(parsed_embed_url)\n", "path": "lib/streamlit/elements/plotly_chart.py"}], "after_files": [{"content": "# Copyright 2018-2020 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\"\"\"Streamlit support for Plotly charts.\"\"\"\n\nimport json\nimport urllib.parse\n\nfrom streamlit import caching\nfrom streamlit import type_util\n\nfrom streamlit.logger import get_logger\nfrom streamlit.proto.PlotlyChart_pb2 import PlotlyChart as PlotlyChartProto\n\nLOGGER = get_logger(__name__)\n\nSHARING_MODES = set(\n    [\n        # This means the plot will be sent to the Streamlit app rather than to\n        # Plotly.\n        \"streamlit\",\n        # The three modes below are for plots that should be hosted in Plotly.\n        # These are the names Plotly uses for them.\n        \"private\",\n        \"public\",\n        \"secret\",\n    ]\n)\n\n\nclass PlotlyMixin:\n    def plotly_chart(\n        dg,\n        figure_or_data,\n        use_container_width=False,\n        sharing=\"streamlit\",\n        **kwargs,\n    ):\n        \"\"\"Display an interactive Plotly chart.\n\n        Plotly is a charting library for Python. The arguments to this function\n        closely follow the ones for Plotly's `plot()` function. You can find\n        more about Plotly at https://plot.ly/python.\n\n        Parameters\n        ----------\n        figure_or_data : plotly.graph_objs.Figure, plotly.graph_objs.Data,\n            dict/list of plotly.graph_objs.Figure/Data\n\n            See https://plot.ly/python/ for examples of graph descriptions.\n\n        use_container_width : bool\n            If True, set the chart width to the column width. This takes\n            precedence over the figure's native `width` value.\n\n        sharing : {'streamlit', 'private', 'secret', 'public'}\n            Use 'streamlit' to insert the plot and all its dependencies\n            directly in the Streamlit app using plotly's offline mode (default).\n            Use any other sharing mode to send the chart to Plotly chart studio, which\n            requires an account. See https://plotly.com/chart-studio/ for more information.\n\n        **kwargs\n            Any argument accepted by Plotly's `plot()` function.\n\n\n        To show Plotly charts in Streamlit, call `st.plotly_chart`\n        wherever you would call Plotly's `py.plot` or `py.iplot`.\n\n        Example\n        -------\n\n        The example below comes straight from the examples at\n        https://plot.ly/python:\n\n        >>> import streamlit as st\n        >>> import plotly.figure_factory as ff\n        >>> import numpy as np\n        >>>\n        >>> # Add histogram data\n        >>> x1 = np.random.randn(200) - 2\n        >>> x2 = np.random.randn(200)\n        >>> x3 = np.random.randn(200) + 2\n        >>>\n        >>> # Group data together\n        >>> hist_data = [x1, x2, x3]\n        >>>\n        >>> group_labels = ['Group 1', 'Group 2', 'Group 3']\n        >>>\n        >>> # Create distplot with custom bin_size\n        >>> fig = ff.create_distplot(\n        ...         hist_data, group_labels, bin_size=[.1, .25, .5])\n        >>>\n        >>> # Plot!\n        >>> st.plotly_chart(fig, use_container_width=True)\n\n        .. output::\n           https://static.streamlit.io/0.56.0-xTAd/index.html?id=TuP96xX8JnsoQeUGAPjkGQ\n           height: 400px\n\n        \"\"\"\n        # NOTE: \"figure_or_data\" is the name used in Plotly's .plot() method\n        # for their main parameter. I don't like the name, but it's best to\n        # keep it in sync with what Plotly calls it.\n        import streamlit.elements.plotly_chart as plotly_chart\n\n        plotly_chart_proto = PlotlyChartProto()\n        marshall(\n            plotly_chart_proto, figure_or_data, use_container_width, sharing, **kwargs\n        )\n        return dg._enqueue(\"plotly_chart\", plotly_chart_proto)  # type: ignore\n\n\ndef marshall(proto, figure_or_data, use_container_width, sharing, **kwargs):\n    \"\"\"Marshall a proto with a Plotly spec.\n\n    See DeltaGenerator.plotly_chart for docs.\n    \"\"\"\n    # NOTE: \"figure_or_data\" is the name used in Plotly's .plot() method\n    # for their main parameter. I don't like the name, but its best to keep\n    # it in sync with what Plotly calls it.\n\n    import plotly.tools\n\n    if type_util.is_type(figure_or_data, \"matplotlib.figure.Figure\"):\n        figure = plotly.tools.mpl_to_plotly(figure_or_data)\n\n    else:\n        figure = plotly.tools.return_figure_from_figure_or_data(\n            figure_or_data, validate_figure=True\n        )\n\n    if not isinstance(sharing, str) or sharing.lower() not in SHARING_MODES:\n        raise ValueError(\"Invalid sharing mode for Plotly chart: %s\" % sharing)\n\n    proto.use_container_width = use_container_width\n\n    if sharing == \"streamlit\":\n        import plotly.utils\n\n        config = dict(kwargs.get(\"config\", {}))\n        # Copy over some kwargs to config dict. Plotly does the same in plot().\n        config.setdefault(\"showLink\", kwargs.get(\"show_link\", False))\n        config.setdefault(\"linkText\", kwargs.get(\"link_text\", False))\n\n        proto.figure.spec = json.dumps(figure, cls=plotly.utils.PlotlyJSONEncoder)\n        proto.figure.config = json.dumps(config)\n\n    else:\n        url = _plot_to_url_or_load_cached_url(\n            figure, sharing=sharing, auto_open=False, **kwargs\n        )\n        proto.url = _get_embed_url(url)\n\n\n@caching.cache\ndef _plot_to_url_or_load_cached_url(*args, **kwargs):\n    \"\"\"Call plotly.plot wrapped in st.cache.\n\n    This is so we don't unecessarily upload data to Plotly's SASS if nothing\n    changed since the previous upload.\n    \"\"\"\n    try:\n        # Plotly 4 changed its main package.\n        import chart_studio.plotly as ply\n    except ImportError:\n        import plotly.plotly as ply\n\n    return ply.plot(*args, **kwargs)\n\n\ndef _get_embed_url(url):\n    parsed_url = urllib.parse.urlparse(url)\n\n    # Plotly's embed URL is the normal URL plus \".embed\".\n    # (Note that our use namedtuple._replace is fine because that's not a\n    # private method! It just has an underscore to avoid clashing with the\n    # tuple field names)\n    parsed_embed_url = parsed_url._replace(path=parsed_url.path + \".embed\")\n\n    return urllib.parse.urlunparse(parsed_embed_url)\n", "path": "lib/streamlit/elements/plotly_chart.py"}]}