@@ -365,6 +365,20 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
365
365
}
366
366
}
367
367
</ style >
368
+ < template id ="colabNotSupported " preserve-content >
369
+ < div style ="max-width: 540px; margin: 80px auto 0 auto; ">
370
+ < h3 > Dynamic plugin isn’t supported in Colab yet.</ h3 >
371
+ < p >
372
+ Please see
373
+ < a
374
+ href ="https://github.com/tensorflow/tensorboard/issues/1913 "
375
+ rel ="noopener "
376
+ target ="_blank "
377
+ > GitHub issue #1913</ a >
378
+ for more information.
379
+ </ p >
380
+ </ div >
381
+ </ template >
368
382
</ template >
369
383
< script src ="autoReloadBehavior.js "> </ script >
370
384
< script >
@@ -581,7 +595,12 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
581
595
_refreshing : {
582
596
type : Boolean ,
583
597
value : false ,
584
- }
598
+ } ,
599
+ _inColab : {
600
+ type : Boolean ,
601
+ value : ( ) => ! ! ( window . TENSORBOARD_ENV || { } ) . IN_COLAB ,
602
+ readOnly : true ,
603
+ } ,
585
604
} ,
586
605
observers : [
587
606
( '_updateSelectedDashboardFromActive(' +
@@ -757,26 +776,8 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
757
776
break ;
758
777
}
759
778
case 'IFRAME' : {
760
- const iframe = document . createElement ( 'iframe' ) ;
761
- iframe . id = 'dashboard' ; // used in `_selectedDashboardComponent`
762
- this . scopeSubtree ( iframe ) ;
763
- container . appendChild ( iframe ) ;
764
- const subdocument = iframe . contentDocument ;
765
- const pluginBasePath = tf_backend . getRouter ( )
766
- . pluginRoute ( selectedDashboard , '/' )
767
- const base = subdocument . createElement ( 'base' ) ;
768
- // TODO(stephanwlee): Use sanitized URL when setting the href.
769
- // setAttribute is a bypass for the security conformance which we
770
- // have no way to address.
771
- base . setAttribute (
772
- 'href' ,
773
- String ( new URL ( pluginBasePath , window . location . href ) ) ) ;
774
- subdocument . head . appendChild ( base ) ;
775
- const script = subdocument . createElement ( 'script' ) ;
776
- const moduleString = JSON . stringify ( loadingMechanism . modulePath ) ;
777
- script . textContent =
778
- `import(${ moduleString } ).then((m) => void m.render());` ;
779
- subdocument . body . appendChild ( script ) ;
779
+ this . _renderPluginIframe (
780
+ container , selectedDashboard , loadingMechanism ) ;
780
781
break ;
781
782
}
782
783
default : {
@@ -788,6 +789,37 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
788
789
this . set ( '_isReloadDisabled' , dashboard . disableReload ) ;
789
790
} ,
790
791
792
+ _renderPluginIframe ( container , selectedDashboard , loadingMechanism ) {
793
+ if ( this . _inColab ) {
794
+ const templateContent = this . $ . colabNotSupported . content ;
795
+ const node = document . importNode ( templateContent , true ) ;
796
+ node . id = 'dashboard' ; // used in `_selectedDashboardComponent`
797
+ this . scopeSubtree ( node ) ;
798
+ container . appendChild ( node ) ;
799
+ return ;
800
+ }
801
+ const iframe = document . createElement ( 'iframe' ) ;
802
+ iframe . id = 'dashboard' ; // used in `_selectedDashboardComponent`
803
+ this . scopeSubtree ( iframe ) ;
804
+ container . appendChild ( iframe ) ;
805
+ const subdocument = iframe . contentDocument ;
806
+ const pluginBasePath = tf_backend . getRouter ( )
807
+ . pluginRoute ( selectedDashboard , '/' )
808
+ const base = subdocument . createElement ( 'base' ) ;
809
+ // TODO(stephanwlee): Use sanitized URL when setting the href.
810
+ // setAttribute is a bypass for the security conformance which we
811
+ // have no way to address.
812
+ base . setAttribute (
813
+ 'href' ,
814
+ String ( new URL ( pluginBasePath , window . location . href ) ) ) ;
815
+ subdocument . head . appendChild ( base ) ;
816
+ const script = subdocument . createElement ( 'script' ) ;
817
+ const moduleString = JSON . stringify ( loadingMechanism . modulePath ) ;
818
+ script . textContent =
819
+ `import(${ moduleString } ).then((m) => void m.render());` ;
820
+ subdocument . body . appendChild ( script ) ;
821
+ } ,
822
+
791
823
/**
792
824
* Get the Polymer component corresponding to the currently
793
825
* selected dashboard. For instance, the result might be an
0 commit comments