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

PDF Viewer isn't loading when called in tabs or expanders #56

Closed
hamdi3 opened this issue Jul 26, 2024 · 5 comments
Closed

PDF Viewer isn't loading when called in tabs or expanders #56

hamdi3 opened this issue Jul 26, 2024 · 5 comments
Milestone

Comments

@hamdi3
Copy link

hamdi3 commented Jul 26, 2024

When trying to render PDFs in a streamlit tab, it only works for the tab that is selected when the page loads.
I've also seen the same behavior when rendering inside streamlit extenders.

The code is as follows:

paths = glob("../../*/*.pdf")
for i, (path, tab) in enumerate(zip(paths, streamlit.tabs(paths))):
  with tab:
      with streamlit.container(border=True):
          pdf_viewer(path, height = 490, render_text = True, key=f"key_{i}")
          streamlit.info(f"read from {path}")

What I've tried so far:

  • Wrote an extra function with pdf_viewer as return value.
  • Stored multiple instances of pdf_viewer in a dict and variables to make sure it wasn't an overwrite issue. (Even tried to save them in the session parameters).
  • Tried all available rendering methods for the function.

I would really appreciate it if you have a workaround.

Thanks in advance!

EDIT: I've seen the other Issue with streamlit tabs so I was wondering if it is in your plans to fix it later and if it's the same issues with expenders.

@lfoppiano
Copy link
Owner

Hi @hamdi3, thanks for reporting the issue.

There is an issue that looks similar (#53), I tried to look for the cause and for see if I could find a workaround but i did not manage. What I understood is that if the tab is not selected, the underlying iframe does not get the correct dimension and the pdf is not shown.

I wish I could spend more time to try to fix it rapidly because is indeed an annoying problem.

@lfoppiano lfoppiano added this to the 0.0.15 milestone Jul 30, 2024
@lfoppiano
Copy link
Owner

This should be solved in the PR #58. If you could test it that would be good. The instructions to install the modified version are here.

Thanks a lot

@lfoppiano
Copy link
Owner

I've released the version 0.0.15. It's not yet officially published, but it's on pypi. Could you please give it a try?

@hamdi3
Copy link
Author

hamdi3 commented Aug 5, 2024

Here's the same results I've commented on the PR

Thanks for the update and the new version :)
After testing it myself i came across the following:

  • The width of the pdf viewer is automatically set to view at least the full page, meaning you can't increase in a way it would zoom in showing half a page in full width (This was possible before).
  • Setting render_text to true would cause the following error m.renderTextLayer is not a function.
  • On the bright side it works with tabs now :)

@lfoppiano
Copy link
Owner

@hamdi3 feel free to close this issue

@hamdi3 hamdi3 closed this as completed Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants