11import asyncio
2+ import html
23
34from .util import parse_event_message
45from lightweight_charts import abstract
@@ -33,12 +34,14 @@ def callback(self, message):
3334 emit_callback (self .win , message )
3435
3536try :
36- from streamlit .components .v1 import html
37+ from streamlit .components .v1 import html as sthtml
3738except ImportError :
38- html = None
39+ sthtml = None
3940
4041try :
4142 from IPython .display import HTML , display
43+ import warnings
44+ warnings .filterwarnings ("ignore" , category = UserWarning , module = "IPython.core.display" )
4245except ImportError :
4346 HTML = None
4447
@@ -129,9 +132,9 @@ def __init__(self, width=None, height=None, inner_width=1, inner_height=1, scale
129132 super ().__init__ (width , height , inner_width , inner_height , scale_candles_only , toolbox )
130133
131134 def _load (self ):
132- if html is None :
135+ if sthtml is None :
133136 raise ModuleNotFoundError ('streamlit.components.v1.html was not found, and must be installed to use StreamlitChart.' )
134- html (f'{ self ._html } </script></body></html>' , width = self .width , height = self .height )
137+ sthtml (f'{ self ._html } </script></body></html>' , width = self .width , height = self .height )
135138
136139
137140class JupyterChart (StaticLWC ):
@@ -153,4 +156,6 @@ def __init__(self, width: int = 800, height=350, inner_width=1, inner_height=1,
153156 def _load (self ):
154157 if HTML is None :
155158 raise ModuleNotFoundError ('IPython.display.HTML was not found, and must be installed to use JupyterChart.' )
156- display (HTML (f'{ self ._html } </script></body></html>' ))
159+ html_code = html .escape (f"{ self ._html } </script></body></html>" )
160+ iframe = f'<iframe width="{ self .width } " height="{ self .height } " frameBorder="0" srcdoc="{ html_code } "></iframe>'
161+ display (HTML (iframe ))
0 commit comments