rendering pdf
I'm running this app in a docker container and exposing it through a port to the browser.
Problem: the browser can't find the pdf to render.
I thought I'd applied the same logic in https://solara.dev/documentation/advanced/reference/static-files but I seem to be missing something.
I have verified that the pdf is correctly generated and in the right path within the container's filesystem. I suspect that there is a path inconsistency when rendering on my host machine's browser. I thought that's what the
static/
logic was supposed to solve?
Thank you for your timeUsing static files and resources in your Solara application
When using Solara, you can host static files, like images, which will then be available at /static/public, in the ../public folder.
7 Replies
I think you forgot the 'public' part, i.e.
image_url = "/static/public/beach.jpeg"
For the rest is looks good!Although, I would put the generate_pdf in a use_task, and only show the iframe when the task is done (i.,e. when the file is written) you could use https://solara.dev/documentation/components/lab/use_task
Replaced with
use_task
. It is more appropriate, thanks!
I was already using "public/"
in the pdf path though, I made it clearer.
Here is what my project structure looks like:
The browser just shows A widget with mount-id="solara-main" should go here
But, a basic button does work? Or do you see this "A widget with ... should go here" in the iframe?
ah, but your file layout is incorrect, the public dir should be ../public WRT the python file
Many people hit that issue, we just want to avoid people putting code in public/foobar.py, and then basically leaking that code, that's why it should be 1 lever higher than the code
Oh I see, indeed, I'll fix that tonight, thanks!
(Yeah other basic components work)
only show the iframe when the task is done (i.,e. when the file is written)Did you mean something like this?
Yeah!
Yep, reorganizing project structure to have
../public
relative to the running .py worked! Thank you 🙏