Skip to content
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

Raise error if embed-resources: true #12

Open
muellerzr opened this issue Jun 5, 2023 · 7 comments
Open

Raise error if embed-resources: true #12

muellerzr opened this issue Jun 5, 2023 · 7 comments

Comments

@muellerzr
Copy link

muellerzr commented Jun 5, 2023

Hi all!

Love the project :)

Hit a fun snag when I was getting a recent blog up and going where if embed-resources:true is set in my _quarto.yml, shinylive just won't render!

Minimal repr:

YAML:

project:
  type: website
format:
  html:
    css: styles.css
    embed-resources: true

somepage.qmd:

# A test

```{shinylive-python}
#| components: [editor, terminal]

def hello_world():
  "Something that prints Hello World"
  return "Hello World"
 

hello_world()
```

Result:
image

Whereas normally I'd expect a shinylive app to be there!

Note that if I don't have embed-resources, it works fine :) Thanks!

@wch
Copy link
Collaborator

wch commented Jun 7, 2023

I haven't taken a look at how the output, but there's a lot of dynamically loaded stuff (wasm files, wheels, and others), and unfortunately, I don't think it will be possible to embed all those resources into the page -- I don't even know how quarto would be able to know about them, since some of the files (like wheels) are only known about at run time.

@muellerzr
Copy link
Author

No worries. Could it be possible to raise an error if that's being set?

@wch
Copy link
Collaborator

wch commented Jun 7, 2023

I think that probably can be done, but I'll have do a bit of investigation to figure out how.

@muellerzr
Copy link
Author

That'd be great if so, otherwise this issue also can act as a quick find for folks that try the same thing 😅

@mcaruel
Copy link

mcaruel commented Nov 7, 2023

I recommend writing this as a prerequisite in the Readme file

@matthewt-assurity
Copy link

Any updates on this?

I'm trying to do the exact same thing, but as @wch said above , it sounds like it's not possible to create a completely self-contained HTML file that contains a shinylive codeblock?

The idea of raising an error sounds good, then it at least gives the user some more information that it won't work.

@gadenbuie gadenbuie changed the title Issue with embed-resources: true and shinylive Raise error if embed-resources: true Jul 12, 2024
@gadenbuie
Copy link
Collaborator

It turns out that shinylive's Lua filter won't have access to the embed-resources option and therefore we can't detect that embed-resources: true is set to be able to throw an error. Quarto may add that to the metadata it passes to the Lua filters in the future, in which case we can throw early.

In the mean time, I've come up with a hacky but workable solution. When shinylive is used with embed-resources: true, the original code chunk is shown in full instead of the shinylive app.

So we can add some warning code to the top of the code chunk that only shows up when shinylive fails to load. The top of the code chunk always contains the chunk options, so we need to use the same syntax:

#| '!! shinylive warning !!': |
#|   shinylive does not work in self-contained HTML documents.
#|   Please set `embed-resources: false` in your metadata.

Hopefully this gives enough information to the person with the broken output to figure out what's going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants