lfoppiano / streamlit-pdf-viewer

Streamlit PDF viewer
https://structure-vision.streamlit.app/
Apache License 2.0
93 stars 6 forks source link

Problem implementing pdf_viewer in st.tabs #53

Closed OliverPSZ closed 1 month ago

OliverPSZ commented 3 months ago

I'm quite new in Streamlit and as stated in the title I have been facing problems trying to implement the pdf viewer in my project. My solution has a set of st.tabs and I need to display a different pdf on each one of them but for now when I run my code it only renders the one from the tab that is open when the app is refreshed, when I switch tabs the rest remain blank.

When I use an st.markdown with an iframe () it works but only on Firefox but not on Chrome or Edge.

lfoppiano commented 3 months ago

Hi @OliverPSZ, could you please share a working example?

moscaAle29 commented 2 months ago

Hi @lfoppiano , having a similar issue here I have a set of references in one tab and, based on the selected reference, a second tab should display the associated pdf and page. the code goes something like this:

ref, docs = st.tabs(["References","Docs"]) with ref:

logic to select a reference

with docs: page=st.session_state.page pdf_viewer(st.session_state.document, pages_to_render=[page-1,page,page+1], width=1000)

As of now this doesn't work BUT If I modify something in the code and click "rerun" while being in the correct tab it works as expected is there a workaround ?

lfoppiano commented 2 months ago

I think the issue is that the document is not attached to the children of the correct tab. One workaround, I think, would be to have the "doc" tab selected when you call the pdf_viewer(), so that the viewer is correct when rendered. An alternative would be to display the references on 1) a different columns instead of tabs, or, 2) in the sidebar. I'm not sure how much users like to click back and forth on the tabs when they have to inspect multiple references. But this is just my humble opinion. 😅

The problem comes on a problem I have encountered a few times already, which is on how to calculate correctly the height of the pages, when the tab of the pdf is not visible everything gets to 0 and the pages are not shown.

lfoppiano commented 1 month ago

I'm closing this as it's a duplicate of #56. Feel free to continue the discussion there.