mljar / mercury

Convert Jupyter Notebooks to Web Apps

Home Page:https://RunMercury.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PDF widget not function properly

tinidoooooooog opened this issue · comments

Hi,

I have an example pdf file and the simple code is run as follows:

import mercury as mr
app = mr.App(title="show pdf", description="show pdf", allow_download=False)
mr.PDF("example.pdf")

but nothing displayed. Can you help please fix this bug?

Hi @tinidoooooooog,

Could you please double check if file example.pdf exists in your directory and is accessible with provided path. I've just checked and it looks like this on my machine

image

What is your use case? What would you like to build with Mercury?

@apjanusz I think we are missing docs/example/tutorial for displaying PDF in Jupyter notebooks and Mercury.

Thanks for quick response.

I am running Mercury using docker +nginx on my remote machine instead of on my local machine (btw, PDF viewer works normally in my local version of mercury as well)

I am doubting if the problem occurs as the IFrame function is called
Could you please give me some suggestions? Thanks!

Do you get error when trying to access file with some other Python code?

content = None
with open(file_path, "rb") as fin:
    content = fin.read()

@apjanusz could you please check if there is a good error message if we try to access not existing pdf file.

In my case,
error message show up correctly file does not exist and no message pop up if existing pdf file name is given.

@pplonski I found the root cause to this issue. The issue comes from the Data URI limitations. In Firefox, the size limitations are looser than in Chromium-based browsers (<1.5 MB) so mr.PDF works as expected in Firefox.

It would be helpful If you can help fix this using approaches not based on data URI. Thank you!

I resolved the issue. By saving the file in the media folder, one can access it via
from IPython.display import Iframe
filepath = '/app/mercury/media/abcde12331/example.pdf' # assuming this

#extract media/abcde12331/example.pdf from {filepath}
url=os.environ.get("MERCURY_SERVER_URL"),'/'.join(filepath.split()[3:])
display(Iframe(src=url,width=width, height=height))