You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you would like to embed a app pyodide/ pyscript app in another html document. And maybe you don't want or cannot host the panel convert assets externally.
One use case is plugins/ filters/ extension to document frameworks like Sphinx, mkDocs or Quarto.
Here you would need code like the below
importhtmlfromioimportStringIOimportsysfrompanel.io.convertimportscript_to_htmlfrompanel.io.resourcesimportset_resource_modeALLOW="accelerometer;autoplay;camera;document-domain;encrypted-media;fullscreen;gamepad;geolocation;gyroscope;layout-animations;legacy-image-formats;microphone;oversized-images;payment;publickey-credentials-get;speaker-selection;sync-xhr;unoptimized-images;unsized-media;screen-wake-lock;web-share;xr-spatial-tracking"defscript_to_iframe(code: str, runtime: str="pyscript")->str:
"""Converts the code to a valid iframe for embedding"""ifruntime=="pyodide-worker":
# The pyodide-worker runtime generates an both a html and a js fileraiseValueError("pyodide-worker runtime is not supported!")
withset_resource_mode('cdn'):
ht, _=script_to_html(
StringIO(script), runtime=runtime
)
ht=html.escape(ht)
returnf"""<iframe frameborder="0" srcdoc="{ht}" class="panel-app" onload="resizePanelApp(this)" allow="{ALLOW}"></iframe>"""
Its tedious to have to develop and maintain this in many settings.
It would be nice if Panel included a ready to use script_to_iframe function.
Additional Context
the pyodide-worker is not supported by the above implementation. The external js worker would need to be hosted externally by panel (without the code) or embedded in the html document generated via a blob url. See https://gist.github.com/nolanlawson/23eff93d27ad09ff44b7e4d56ffd1d54. The pyoide-worker runtime loading looks much nicer than the pyscript loading. Thus I would prefer to be able to use that one.
The limitation of the script_to_iframe is that it does not work well if you want to embed many panel apps in a page because each iframe loads all the resources etc. Shiny-live solves this by loading once outside the iframe and then setting up a communication channel between parent window and iframe.
I think the line with set_resource_mode('cdn') is a hack and some refactoring of Panel code should be done so that this can be avoided.
The text was updated successfully, but these errors were encountered:
Sometimes you would like to embed a app pyodide/ pyscript app in another html document. And maybe you don't want or cannot host the
panel convert
assets externally.One use case is plugins/ filters/ extension to document frameworks like Sphinx, mkDocs or Quarto.
Here you would need code like the below
Its tedious to have to develop and maintain this in many settings.
It would be nice if Panel included a ready to use
script_to_iframe
function.Additional Context
pyodide-worker
is not supported by the above implementation. The external js worker would need to be hosted externally by panel (without the code) or embedded in the html document generated via a blob url. See https://gist.github.com/nolanlawson/23eff93d27ad09ff44b7e4d56ffd1d54. The pyoide-worker runtime loading looks much nicer than the pyscript loading. Thus I would prefer to be able to use that one.script_to_iframe
is that it does not work well if you want to embed many panel apps in a page because each iframe loads all the resources etc. Shiny-live solves this by loading once outside the iframe and then setting up a communication channel between parent window and iframe.with set_resource_mode('cdn')
is a hack and some refactoring of Panel code should be done so that this can be avoided.The text was updated successfully, but these errors were encountered: