Преглед на файлове

fix: bokeh show chart error

wangweimin преди 4 години
родител
ревизия
26a3aa38a9
променени са 4 файла, в които са добавени 40 реда и са изтрити 46 реда
  1. 0 21
      pywebio/html/index.html
  2. 39 3
      pywebio/platform/bokeh.py
  3. 0 21
      pywebio/platform/tpl/index.html
  4. 1 1
      test/11.charts.py

+ 0 - 21
pywebio/html/index.html

@@ -69,28 +69,7 @@
     require.config({
         paths: {
             'plotly': "https://cdn.jsdelivr.net/npm/plotly.js@1.53.0/dist/plotly.min", // 'https://cdn.plot.ly/plotly-latest.min'
-            "bokeh": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh.min",
-            "bokeh-widgets": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh-widgets.min",
-            "bokeh-tables": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh-tables.min",
-            "bokeh-gl": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh-gl.min",
         },
-        shim: {
-            'bokeh': {
-                exports: 'Bokeh'
-            },
-            'bokeh-widgets': {
-                exports: '_',
-                deps: ['bokeh'],
-            },
-            'bokeh-tables': {
-                exports: '_',
-                deps: ['bokeh'],
-            },
-            'bokeh-gl': {
-                exports: '_',
-                deps: ['bokeh'],
-            },
-        }
     });
 
 

+ 39 - 3
pywebio/platform/bokeh.py

@@ -5,10 +5,45 @@ from collections.abc import Sequence
 from pywebio.output import *
 from pywebio.session import get_info
 
+requirejs_config_tpl = """
+<script type="text/javascript">
+require.config({
+    paths: {
+        "bokeh": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@__version__/build/js/bokeh.min",
+        "bokeh-widgets": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@__version__/build/js/bokeh-widgets.min",
+        "bokeh-tables": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@__version__/build/js/bokeh-tables.min",
+        "bokeh-api": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@__version__/build/js/bokeh-api.min",
+        "bokeh-gl": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@__version__/build/js/bokeh-gl.min",
+    },
+    shim: {
+        'bokeh': {
+            exports: 'Bokeh'
+        },
+        'bokeh-widgets': {
+            exports: '_',
+            deps: ['bokeh'],
+        },
+        'bokeh-tables': {
+            exports: '_',
+            deps: ['bokeh'],
+        },
+        'bokeh-api': {
+            exports: '_',
+            deps: ['bokeh'],
+        },
+        'bokeh-gl': {
+            exports: '_',
+            deps: ['bokeh'],
+        },
+    }
+});
+</script>
+"""
+
 requirejs_tpl = """
 %s
 <script type="text/javascript">
-requirejs(['bokeh', 'bokeh-widgets', 'bokeh-tables', 'bokeh-gl'], function(Bokeh) {
+requirejs(['bokeh', 'bokeh-widgets', 'bokeh-tables'], function(Bokeh) {
     %s
 });
 </script>
@@ -24,11 +59,12 @@ def load_notebook(resources=None, verbose=False, hide_banner=False, load_timeout
     :param load_timeout: 不支持
     :return: None
     """
+    from bokeh import __version__
     from bokeh.util.serialization import make_id
 
     js_gists = ["console.log('Load BokehJS complete.')"]
 
-    html = ''
+    html = requirejs_config_tpl.replace('__version__', __version__)
     if verbose:
         element_id = make_id()
         html += """
@@ -109,7 +145,7 @@ def show_app(app, state, notebook_url, port=0, **kw):
 
     script = re.sub(r'<script(.*?)>([\s\S]*?)</script>', r"""
     <script \g<1>>
-        requirejs(['bokeh', 'bokeh-widgets', 'bokeh-tables', 'bokeh-gl'], function(Bokeh) {
+        requirejs(['bokeh', 'bokeh-widgets', 'bokeh-tables'], function(Bokeh) {
             \g<2>
         });
     </script>

+ 0 - 21
pywebio/platform/tpl/index.html

@@ -61,28 +61,7 @@
     require.config({
         paths: {
             'plotly': "https://cdn.jsdelivr.net/npm/plotly.js@1.53.0/dist/plotly.min", // 'https://cdn.plot.ly/plotly-latest.min'
-            "bokeh": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh.min",
-            "bokeh-widgets": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh-widgets.min",
-            "bokeh-tables": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh-tables.min",
-            "bokeh-gl": "https://cdn.jsdelivr.net/npm/@bokeh/bokehjs@2.0.2/build/js/bokeh-gl.min",
         },
-        shim: {
-            'bokeh': {
-                exports: 'Bokeh'
-            },
-            'bokeh-widgets': {
-                exports: '_',
-                deps: ['bokeh'],
-            },
-            'bokeh-tables': {
-                exports: '_',
-                deps: ['bokeh'],
-            },
-            'bokeh-gl': {
-                exports: '_',
-                deps: ['bokeh'],
-            },
-        }
     });
 
 

+ 1 - 1
test/11.charts.py

@@ -375,7 +375,7 @@ def target():
 
 
 def test(server_proc: subprocess.Popen, browser: Chrome):
-    time.sleep(15)
+    time.sleep(8)
     percySnapshot(browser, name='bokeh')