KevinGG commented on a change in pull request #11020: [BEAM-7926] Update Data 
Visualization
URL: https://github.com/apache/beam/pull/11020#discussion_r387315589
 
 

 ##########
 File path: 
sdks/python/apache_beam/runners/interactive/interactive_environment.py
 ##########
 @@ -43,6 +43,55 @@
 
 _LOGGER = logging.getLogger(__name__)
 
+# By `format(customized_script=xxx)`, the given `customized_script` is
+# guaranteed to be executed within access to a jquery with datatable plugin
+# configured which is useful so that any `customized_script` is resilient to
+# browser refresh. Inside `customized_script`, use `$` as jQuery.
+_JQUERY_WITH_DATATABLE_TEMPLATE = """
+        if (typeof window.jquery341 == 'undefined') {{
+          var jqueryScript = document.createElement('script');
+          jqueryScript.src = 
'https://code.jquery.com/jquery-3.4.1.slim.min.js';
+          jqueryScript.type = 'text/javascript';
+          jqueryScript.onload = function() {{
+            var datatableScript = document.createElement('script');
+            datatableScript.src = 
'https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js';
+            datatableScript.type = 'text/javascript';
+            datatableScript.onload = function() {{
+              window.jquery341 = jQuery.noConflict(true);
+              window.jquery341(document).ready(function($){{
+                {customized_script}
+              }});
+            }}
+            document.head.appendChild(datatableScript);
+          }};
+          document.head.appendChild(jqueryScript);
+        }} else {{
+          window.jquery341(document).ready(function($){{
+            {customized_script}
+          }});
+        }}"""
+
+_HTML_IMPORT_TEMPLATE = """
 
 Review comment:
   This uses something called `HTML import` where static HTML will be imported 
and embedded into current HTML.
   Here the HTML we desire is facets-jupyter.html.
   
   This feature is not supported by chrome anymore, thus requires the 
webcomponents JS lib.
   Similar to the jQuery template, we check if `HTML import` is supported by 
the browser, if so, import HTMLs else setup webcomponents and chain the `HTML 
import` to the end of `onload`.
   Note, we import HTMLs in the head for several reasons:
   1. In a notebook, DOM changes all the time. Keeping imported HTMLs in head 
makes sure all dependency HTMLs available all the time.
   2. `HTML import` only happens once per page load. There is no way to recover 
an imported HTML if you delete it from DOM unless you refresh the page.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to