We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
HTML renderer should use uuid in chart divs
Currently, divs are generated via chart counts. This means that if a kernel is restarted in the notebook, new charts may not display correctly.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `altair/utils/display.py`
Content:
```
1 import json
2 import pkgutil
3 import textwrap
4 from typing import Callable, Dict
5 
6 from jsonschema import validate
7 
8 from .plugin_registry import PluginRegistry
9 from .mimebundle import spec_to_mimebundle
10 
11 
12 # ==============================================================================
13 # Renderer registry
14 # ==============================================================================
15 MimeBundleType = Dict[str, object]
16 RendererType = Callable[..., MimeBundleType]
17 
18 
19 class RendererRegistry(PluginRegistry[RendererType]):
20     entrypoint_err_messages = {
21         'notebook': textwrap.dedent(
22             """
23             To use the 'notebook' renderer, you must install the vega package
24             and the associated Jupyter extension.
25             See https://altair-viz.github.io/getting_started/installation.html
26             for more information.
27             """),
28         'vegascope': textwrap.dedent(
29             """
30             To use the 'vegascope' renderer, you must install the vegascope
31             package; see http://github.com/diana-hep/vegascope/
32             for more information.
33             """),
34     }
35 
36     def set_embed_options(self, defaultStyle=None, renderer=None,
37                           width=None, height=None, padding=None,
38                           scaleFactor=None, actions=None, **kwargs):
39         """Set options for embeddings of Vega & Vega-Lite charts.
40 
41         Options are fully documented at https://github.com/vega/vega-embed.
42         Similar to the `enable()` method, this can be used as either
43         a persistent global switch, or as a temporary local setting using
44         a context manager (i.e. a `with` statement).
45 
46         Parameters
47         ----------
48         defaultStyle : bool or string
49             Specify a default stylesheet for embed actions.
50         renderer : string
51             The renderer to use for the view. One of "canvas" (default) or "svg"
52         width : integer
53             The view width in pixels
54         height : integer
55             The view height in pixels
56         padding : integer
57             The view padding in pixels
58         scaleFactor : number
59             The number by which to multiply the width and height (default 1)
60             of an exported PNG or SVG image.
61         actions : bool or dict
62             Determines if action links ("Export as PNG/SVG", "View Source",
63             "View Vega" (only for Vega-Lite), "Open in Vega Editor") are
64             included with the embedded view. If the value is true, all action
65             links will be shown and none if the value is false. This property
66             can take a key-value mapping object that maps keys (export, source,
67             compiled, editor) to boolean values for determining if
68             each action link should be shown.
69         **kwargs :
70             Additional options are passed directly to embed options.
71         """
72         options = {'defaultStyle': defaultStyle, 'renderer': renderer,
73                    'width': width, 'height': height, 'padding': padding,
74                    'scaleFactor': scaleFactor, 'actions': actions}
75         kwargs.update({key: val for key, val in options.items()
76                        if val is not None})
77         return self.enable(None, embed_options=kwargs)
78 
79 
80 # ==============================================================================
81 # VegaLite v1/v2 renderer logic
82 # ==============================================================================
83 
84 
85 class Displayable(object):
86     """A base display class for VegaLite v1/v2.
87 
88     This class takes a VegaLite v1/v2 spec and does the following:
89 
90     1. Optionally validates the spec against a schema.
91     2. Uses the RendererPlugin to grab a renderer and call it when the
92        IPython/Jupyter display method (_repr_mimebundle_) is called.
93 
94     The spec passed to this class must be fully schema compliant and already
95     have the data portion of the spec fully processed and ready to serialize.
96     In practice, this means, the data portion of the spec should have been passed
97     through appropriate data model transformers.
98     """
99 
100     renderers = None
101     schema_path = ('altair', '')
102 
103     def __init__(self, spec, validate=False):
104         # type: (dict, bool) -> None
105         self.spec = spec
106         self.validate = validate
107         self._validate()
108 
109     def _validate(self):
110         # type: () -> None
111         """Validate the spec against the schema."""
112         schema_dict = json.loads(pkgutil.get_data(*self.schema_path).decode('utf-8'))
113         validate(self.spec, schema_dict)
114 
115     def _repr_mimebundle_(self, include, exclude):
116         """Return a MIME bundle for display in Jupyter frontends."""
117         if self.renderers is not None:
118             return self.renderers.get()(self.spec)
119         else:
120             return {}
121 
122 
123 def default_renderer_base(spec, mime_type, str_repr, **options):
124     """A default renderer for Vega or VegaLite that works for modern frontends.
125 
126     This renderer works with modern frontends (JupyterLab, nteract) that know
127     how to render the custom VegaLite MIME type listed above.
128     """
129     assert isinstance(spec, dict)
130     bundle = {}
131     metadata = {}
132 
133     bundle[mime_type] = spec
134     bundle['text/plain'] = str_repr
135     if options:
136         metadata[mime_type] = options
137     return bundle, metadata
138 
139 
140 def json_renderer_base(spec, str_repr, **options):
141     """A renderer that returns a MIME type of application/json.
142 
143     In JupyterLab/nteract this is rendered as a nice JSON tree.
144     """
145     return default_renderer_base(spec, mime_type='application/json',
146                                  str_repr=str_repr, **options)
147 
148 
149 class HTMLRenderer(object):
150     """Object to render charts as HTML, with a unique output div each time"""
151     def __init__(self, output_div='altair-viz-{}', **kwargs):
152         self._output_div = output_div
153         self._output_count = 0
154         self.kwargs = kwargs
155 
156     @property
157     def output_div(self):
158         self._output_count += 1
159         return self._output_div.format(self._output_count)
160 
161     def __call__(self, spec, **metadata):
162         kwargs = self.kwargs.copy()
163         kwargs.update(metadata)
164         return spec_to_mimebundle(spec, format='html',
165                                   output_div=self.output_div, **kwargs)
166
```
--- 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/altair/utils/display.py b/altair/utils/display.py
--- a/altair/utils/display.py
+++ b/altair/utils/display.py
@@ -2,6 +2,7 @@
 import pkgutil
 import textwrap
 from typing import Callable, Dict
+import uuid
 
 from jsonschema import validate
 
@@ -150,13 +151,11 @@
     """Object to render charts as HTML, with a unique output div each time"""
     def __init__(self, output_div='altair-viz-{}', **kwargs):
         self._output_div = output_div
-        self._output_count = 0
         self.kwargs = kwargs
 
     @property
     def output_div(self):
-        self._output_count += 1
-        return self._output_div.format(self._output_count)
+        return self._output_div.format(uuid.uuid4().hex)
 
     def __call__(self, spec, **metadata):
         kwargs = self.kwargs.copy()

{"golden_diff": "diff --git a/altair/utils/display.py b/altair/utils/display.py\n--- a/altair/utils/display.py\n+++ b/altair/utils/display.py\n@@ -2,6 +2,7 @@\n import pkgutil\n import textwrap\n from typing import Callable, Dict\n+import uuid\n \n from jsonschema import validate\n \n@@ -150,13 +151,11 @@\n     \"\"\"Object to render charts as HTML, with a unique output div each time\"\"\"\n     def __init__(self, output_div='altair-viz-{}', **kwargs):\n         self._output_div = output_div\n-        self._output_count = 0\n         self.kwargs = kwargs\n \n     @property\n     def output_div(self):\n-        self._output_count += 1\n-        return self._output_div.format(self._output_count)\n+        return self._output_div.format(uuid.uuid4().hex)\n \n     def __call__(self, spec, **metadata):\n         kwargs = self.kwargs.copy()\n", "issue": "HTML renderer should use uuid in chart divs\nCurrently, divs are generated via chart counts. This means that if a kernel is restarted in the notebook, new charts may not display correctly.\n", "before_files": [{"content": "import json\nimport pkgutil\nimport textwrap\nfrom typing import Callable, Dict\n\nfrom jsonschema import validate\n\nfrom .plugin_registry import PluginRegistry\nfrom .mimebundle import spec_to_mimebundle\n\n\n# ==============================================================================\n# Renderer registry\n# ==============================================================================\nMimeBundleType = Dict[str, object]\nRendererType = Callable[..., MimeBundleType]\n\n\nclass RendererRegistry(PluginRegistry[RendererType]):\n    entrypoint_err_messages = {\n        'notebook': textwrap.dedent(\n            \"\"\"\n            To use the 'notebook' renderer, you must install the vega package\n            and the associated Jupyter extension.\n            See https://altair-viz.github.io/getting_started/installation.html\n            for more information.\n            \"\"\"),\n        'vegascope': textwrap.dedent(\n            \"\"\"\n            To use the 'vegascope' renderer, you must install the vegascope\n            package; see http://github.com/diana-hep/vegascope/\n            for more information.\n            \"\"\"),\n    }\n\n    def set_embed_options(self, defaultStyle=None, renderer=None,\n                          width=None, height=None, padding=None,\n                          scaleFactor=None, actions=None, **kwargs):\n        \"\"\"Set options for embeddings of Vega & Vega-Lite charts.\n\n        Options are fully documented at https://github.com/vega/vega-embed.\n        Similar to the `enable()` method, this can be used as either\n        a persistent global switch, or as a temporary local setting using\n        a context manager (i.e. a `with` statement).\n\n        Parameters\n        ----------\n        defaultStyle : bool or string\n            Specify a default stylesheet for embed actions.\n        renderer : string\n            The renderer to use for the view. One of \"canvas\" (default) or \"svg\"\n        width : integer\n            The view width in pixels\n        height : integer\n            The view height in pixels\n        padding : integer\n            The view padding in pixels\n        scaleFactor : number\n            The number by which to multiply the width and height (default 1)\n            of an exported PNG or SVG image.\n        actions : bool or dict\n            Determines if action links (\"Export as PNG/SVG\", \"View Source\",\n            \"View Vega\" (only for Vega-Lite), \"Open in Vega Editor\") are\n            included with the embedded view. If the value is true, all action\n            links will be shown and none if the value is false. This property\n            can take a key-value mapping object that maps keys (export, source,\n            compiled, editor) to boolean values for determining if\n            each action link should be shown.\n        **kwargs :\n            Additional options are passed directly to embed options.\n        \"\"\"\n        options = {'defaultStyle': defaultStyle, 'renderer': renderer,\n                   'width': width, 'height': height, 'padding': padding,\n                   'scaleFactor': scaleFactor, 'actions': actions}\n        kwargs.update({key: val for key, val in options.items()\n                       if val is not None})\n        return self.enable(None, embed_options=kwargs)\n\n\n# ==============================================================================\n# VegaLite v1/v2 renderer logic\n# ==============================================================================\n\n\nclass Displayable(object):\n    \"\"\"A base display class for VegaLite v1/v2.\n\n    This class takes a VegaLite v1/v2 spec and does the following:\n\n    1. Optionally validates the spec against a schema.\n    2. Uses the RendererPlugin to grab a renderer and call it when the\n       IPython/Jupyter display method (_repr_mimebundle_) is called.\n\n    The spec passed to this class must be fully schema compliant and already\n    have the data portion of the spec fully processed and ready to serialize.\n    In practice, this means, the data portion of the spec should have been passed\n    through appropriate data model transformers.\n    \"\"\"\n\n    renderers = None\n    schema_path = ('altair', '')\n\n    def __init__(self, spec, validate=False):\n        # type: (dict, bool) -> None\n        self.spec = spec\n        self.validate = validate\n        self._validate()\n\n    def _validate(self):\n        # type: () -> None\n        \"\"\"Validate the spec against the schema.\"\"\"\n        schema_dict = json.loads(pkgutil.get_data(*self.schema_path).decode('utf-8'))\n        validate(self.spec, schema_dict)\n\n    def _repr_mimebundle_(self, include, exclude):\n        \"\"\"Return a MIME bundle for display in Jupyter frontends.\"\"\"\n        if self.renderers is not None:\n            return self.renderers.get()(self.spec)\n        else:\n            return {}\n\n\ndef default_renderer_base(spec, mime_type, str_repr, **options):\n    \"\"\"A default renderer for Vega or VegaLite that works for modern frontends.\n\n    This renderer works with modern frontends (JupyterLab, nteract) that know\n    how to render the custom VegaLite MIME type listed above.\n    \"\"\"\n    assert isinstance(spec, dict)\n    bundle = {}\n    metadata = {}\n\n    bundle[mime_type] = spec\n    bundle['text/plain'] = str_repr\n    if options:\n        metadata[mime_type] = options\n    return bundle, metadata\n\n\ndef json_renderer_base(spec, str_repr, **options):\n    \"\"\"A renderer that returns a MIME type of application/json.\n\n    In JupyterLab/nteract this is rendered as a nice JSON tree.\n    \"\"\"\n    return default_renderer_base(spec, mime_type='application/json',\n                                 str_repr=str_repr, **options)\n\n\nclass HTMLRenderer(object):\n    \"\"\"Object to render charts as HTML, with a unique output div each time\"\"\"\n    def __init__(self, output_div='altair-viz-{}', **kwargs):\n        self._output_div = output_div\n        self._output_count = 0\n        self.kwargs = kwargs\n\n    @property\n    def output_div(self):\n        self._output_count += 1\n        return self._output_div.format(self._output_count)\n\n    def __call__(self, spec, **metadata):\n        kwargs = self.kwargs.copy()\n        kwargs.update(metadata)\n        return spec_to_mimebundle(spec, format='html',\n                                  output_div=self.output_div, **kwargs)\n", "path": "altair/utils/display.py"}], "after_files": [{"content": "import json\nimport pkgutil\nimport textwrap\nfrom typing import Callable, Dict\nimport uuid\n\nfrom jsonschema import validate\n\nfrom .plugin_registry import PluginRegistry\nfrom .mimebundle import spec_to_mimebundle\n\n\n# ==============================================================================\n# Renderer registry\n# ==============================================================================\nMimeBundleType = Dict[str, object]\nRendererType = Callable[..., MimeBundleType]\n\n\nclass RendererRegistry(PluginRegistry[RendererType]):\n    entrypoint_err_messages = {\n        'notebook': textwrap.dedent(\n            \"\"\"\n            To use the 'notebook' renderer, you must install the vega package\n            and the associated Jupyter extension.\n            See https://altair-viz.github.io/getting_started/installation.html\n            for more information.\n            \"\"\"),\n        'vegascope': textwrap.dedent(\n            \"\"\"\n            To use the 'vegascope' renderer, you must install the vegascope\n            package; see http://github.com/diana-hep/vegascope/\n            for more information.\n            \"\"\"),\n    }\n\n    def set_embed_options(self, defaultStyle=None, renderer=None,\n                          width=None, height=None, padding=None,\n                          scaleFactor=None, actions=None, **kwargs):\n        \"\"\"Set options for embeddings of Vega & Vega-Lite charts.\n\n        Options are fully documented at https://github.com/vega/vega-embed.\n        Similar to the `enable()` method, this can be used as either\n        a persistent global switch, or as a temporary local setting using\n        a context manager (i.e. a `with` statement).\n\n        Parameters\n        ----------\n        defaultStyle : bool or string\n            Specify a default stylesheet for embed actions.\n        renderer : string\n            The renderer to use for the view. One of \"canvas\" (default) or \"svg\"\n        width : integer\n            The view width in pixels\n        height : integer\n            The view height in pixels\n        padding : integer\n            The view padding in pixels\n        scaleFactor : number\n            The number by which to multiply the width and height (default 1)\n            of an exported PNG or SVG image.\n        actions : bool or dict\n            Determines if action links (\"Export as PNG/SVG\", \"View Source\",\n            \"View Vega\" (only for Vega-Lite), \"Open in Vega Editor\") are\n            included with the embedded view. If the value is true, all action\n            links will be shown and none if the value is false. This property\n            can take a key-value mapping object that maps keys (export, source,\n            compiled, editor) to boolean values for determining if\n            each action link should be shown.\n        **kwargs :\n            Additional options are passed directly to embed options.\n        \"\"\"\n        options = {'defaultStyle': defaultStyle, 'renderer': renderer,\n                   'width': width, 'height': height, 'padding': padding,\n                   'scaleFactor': scaleFactor, 'actions': actions}\n        kwargs.update({key: val for key, val in options.items()\n                       if val is not None})\n        return self.enable(None, embed_options=kwargs)\n\n\n# ==============================================================================\n# VegaLite v1/v2 renderer logic\n# ==============================================================================\n\n\nclass Displayable(object):\n    \"\"\"A base display class for VegaLite v1/v2.\n\n    This class takes a VegaLite v1/v2 spec and does the following:\n\n    1. Optionally validates the spec against a schema.\n    2. Uses the RendererPlugin to grab a renderer and call it when the\n       IPython/Jupyter display method (_repr_mimebundle_) is called.\n\n    The spec passed to this class must be fully schema compliant and already\n    have the data portion of the spec fully processed and ready to serialize.\n    In practice, this means, the data portion of the spec should have been passed\n    through appropriate data model transformers.\n    \"\"\"\n\n    renderers = None\n    schema_path = ('altair', '')\n\n    def __init__(self, spec, validate=False):\n        # type: (dict, bool) -> None\n        self.spec = spec\n        self.validate = validate\n        self._validate()\n\n    def _validate(self):\n        # type: () -> None\n        \"\"\"Validate the spec against the schema.\"\"\"\n        schema_dict = json.loads(pkgutil.get_data(*self.schema_path).decode('utf-8'))\n        validate(self.spec, schema_dict)\n\n    def _repr_mimebundle_(self, include, exclude):\n        \"\"\"Return a MIME bundle for display in Jupyter frontends.\"\"\"\n        if self.renderers is not None:\n            return self.renderers.get()(self.spec)\n        else:\n            return {}\n\n\ndef default_renderer_base(spec, mime_type, str_repr, **options):\n    \"\"\"A default renderer for Vega or VegaLite that works for modern frontends.\n\n    This renderer works with modern frontends (JupyterLab, nteract) that know\n    how to render the custom VegaLite MIME type listed above.\n    \"\"\"\n    assert isinstance(spec, dict)\n    bundle = {}\n    metadata = {}\n\n    bundle[mime_type] = spec\n    bundle['text/plain'] = str_repr\n    if options:\n        metadata[mime_type] = options\n    return bundle, metadata\n\n\ndef json_renderer_base(spec, str_repr, **options):\n    \"\"\"A renderer that returns a MIME type of application/json.\n\n    In JupyterLab/nteract this is rendered as a nice JSON tree.\n    \"\"\"\n    return default_renderer_base(spec, mime_type='application/json',\n                                 str_repr=str_repr, **options)\n\n\nclass HTMLRenderer(object):\n    \"\"\"Object to render charts as HTML, with a unique output div each time\"\"\"\n    def __init__(self, output_div='altair-viz-{}', **kwargs):\n        self._output_div = output_div\n        self.kwargs = kwargs\n\n    @property\n    def output_div(self):\n        return self._output_div.format(uuid.uuid4().hex)\n\n    def __call__(self, spec, **metadata):\n        kwargs = self.kwargs.copy()\n        kwargs.update(metadata)\n        return spec_to_mimebundle(spec, format='html',\n                                  output_div=self.output_div, **kwargs)\n", "path": "altair/utils/display.py"}]}