-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it as easy as Gradiolite to embed Panel Pyodide into websites #5766
Comments
Example Issue: Using ExtensionsIf you want to use extensions like Tabulator, then its not explained in https://panel.holoviz.org/how_to/wasm/standalone.html how to add support. If users try extending the documented example without adding the relevant js and css dependencies manually, it will fail for them. <!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-3.3.0.js"></script>
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.3.0.min.js"></script>
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.3.0.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@holoviz/panel@1.3.0/dist/panel.min.js"></script>
</head>
<body>
<div id="simple_app"></div>
<script type="text/javascript">
async function main(){
let pyodide = await loadPyodide();
await pyodide.loadPackage("micropip");
const micropip = pyodide.pyimport("micropip");
await micropip.install([
"https://cdn.holoviz.org/panel/1.3.0/dist/wheels/bokeh-3.3.0-py3-none-any.whl",
"https://cdn.holoviz.org/panel/1.3.0/dist/wheels/panel-1.3.0-py3-none-any.whl"]
)
pyodide.runPython(`
import panel as pn
import pandas as pd
pn.extension("tabulator", sizing_mode="stretch_width")
df = pd.DataFrame({
'int': [1, 2, 3],
'float': [3.14, 6.28, 9.42],
'str': ['A', 'B', 'C'],
'bool': [True, False, True],
}, index=[1, 2, 3])
pn.widgets.Tabulator(df).servable(target="simple_app")
`);
}
main();
</script>
</body>
</html> pyodide.asm.js:9 future: <Task finished name='Task-46' coro=<write() done, defined at /lib/python3.11/site-packages/panel/io/pyodide.py:435> exception=ReferenceError: Tabulator is not defined> |
|
I think we need to make a clear distinction here,
Seems like a bug that should be fixed |
After having played with it in #5769 (comment), I can see we could simplify a lot because It can be as simple as <panel-lite>
import panel as pn
pn.extension()
component = pn.panel("Hello World")
pn.template.FastListTemplate(title="Awesome", main=[component]).servable()
<panel-lite> We just need a function In addition we can implement functionality to support hot reload. The key to providing hot reload is to store and reuse the For more details including what |
I think Its much easier to run
And if you are a python framework wanting to embed 5-200 examples on your website then you need to implement your own command to automate this. |
I'm not saying we shouldn't provide functionality for generate an embeddable snippet, I'm saying |
Then you misunderstood me. I'm using the python function behind It works. The main issue to solve is to only load one Pyodide instance. And to share it across iframes if you have multiple iframes embedding Panel pyodide apps in your app. Sharing across iframes seems hard as currently |
Another great option would be to create a quarto extension for Panel Pyodide. I've found that the Shiny quarto extension has made it a lot easier for people to get started with WASM, and we'd be happy to help if you all were interested in that route. This would also be great because it might make it a bit easier to embed panel apps in blog posts. |
The understanding i lack is how to load Pyodide once, But use and reuse it over and over again on the main page and inside iframes. The iframe is important for panel to be able to show our apps in the full templates and individualy styled. I believe it can be done, But how? Do you know @gshotwell ? |
Oh yeah we definitely ran into that with both the R and python quarto versions, but it's now resolved. This is how we're able to host all of our examples with WASM without blowing up our network costs or creating a bunch of lag. The extension separates each application on a page and displays them in an iframe so they don't inherit global themes. For example see these: https://shiny.posit.co/py/docs/ui-styling.html I'm not actually sure of the mechanics of how this is accomplished, but let me ask folks who worked on the extensions. |
From Winston and George: The way we do this is to load Pyodide in a JS Web/Service worker then distribute the work via message passing communication using tools like window.postMessage(). In Shinylive it’s launched in a web worker, and then each iframe talks to the web worker via an interface that looks like a WebSocket, but instead of sending messages across the network, it sends messages across JS threads via postMessage(). |
Thanks Note for self: should try recreate iframe on app rerender instead of trying to reset iframe internals and render |
Thanks @gshotwell . I tried getting quarto installed. My feedback is that its difficult for a Pythonista to get it installed 😄
I would recommend describing how a python user most easily get up and running with quarto in https://quarto.org/docs/computations/python.html. |
That's great feedback @MarcSkovMadsen, I'll pass it on. Does installing the dev version work?
Edit: looks like you can use pip to build quarto, not quite sure why it's not on pypi.
|
$ quarto preview script.qmd --port 5008
ERROR: NotFound: No such file or directory (os error 2)
Path: /opt/conda/share/quarto/formats/html/bslib/components/scss/mixins/_mixins.scss
Stack trace:
Path: /opt/conda/share/quarto/formats/html/bslib/components/scss/mixins/_mixins.scss
at readTextFileSync (deno:runtime/js/40_read_file.js:42:16)
at Object.Deno.readTextFileSync (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:5623:25)
at bslibComponentMixins (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:42998:17)
at layerQuartoScss (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:108756:9)
at resolveBootstrapScss (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:108796:22)
at boostrapExtras (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:109998:25)
at themeFormatExtras (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:111806:16)
at Object.formatExtras (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:111269:111)
at async runPandoc (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:68671:60)
at async renderPandoc (file:///home/jovyan/repos/private/docs-experiments/.venv/lib/python3.11/site-packages/quarto_cli/quarto-1.4.533/bin/quarto.js:69969:26)
|
Drag, would you mind raising a quarto issue? https://github.com/quarto-dev/quarto-cli/issues |
Gradio recently released Gradiolite which makes it super simple to use Gradio in Pyodide and embed it into websites.
I don't think its nearly as easy with Panel because
iframe
is the way to go. If that is our recommendation, we should document it.panel convert
not for embedding: Works really well for single applications. But creates highly bloated files that you don't want to look inside and especially not want to copy-paste manually 10 times into a markdown or html file..html
head.design
is maybe the solution here. Again we should document how to use and not use templates and designs.maintaince
: Its really hard to keep pyodide apps working unless you freeze and pin every requirement. I see these apps broken again and again.nbsite.pyodide
: The panel docs with Pyodide are nice. But for others to replicate that they would have to use Sphinx withnbsite
which will only work for a subset of sites. For example some use MkDocs and some would not like to depend on an external dependency likenbsite
.I see different solutions
panel convert
that can create files/ code optimized for embedding into webpagespanel-lite
web component that hides all the complexity similiar togradio-lite
.Some things that would be super helpful too would be
run
button. If the user clicks the run button the Panel application is then embedding. The experience of the Run Button should be similar to the one in Panels documentation with loading indicator and some text explaining steps.panel-lite
. There is nowjupyterlite
,stlite
for Streamlit andgradio-lite
for Gradio. It will just confuse people we use terminologypanelite
for our version of Jupyterlite and have no terminology for Panel in Pyodide.Additional Context
Improvements here could also make it much easier for Panel users to share and maintain their apps at pyscript.com.
The text was updated successfully, but these errors were encountered: