lfoppiano / streamlit-pdf-viewer

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

pdf not showing #37

Closed trbtl closed 5 months ago

trbtl commented 7 months ago

I’m creating a simple pdf viewer. See the code below. When I click on a button the first time nothing is displayed. When I click on it a second time thh pdf is displayed. What am I doing wrong?

import streamlit as st
from streamlit_pdf_viewer import pdf_viewer
import os

if ‘selected_file’ not in st.session_state:
st.session_state[‘selected_file’] = None

with st.sidebar:
library = st.container()
with library:

    def get_files(directory):
        return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]

    def file_selector(folder_path='.'):
        st.write("Select a document from the list below:")
        files = get_files(folder_path)
        for file in files:
            if st.button(file): 
                st.session_state['selected_file'] = file  

    folder_path = './docs' 
    file_selector(folder_path)
if st.session_state[‘selected_file’] is not None:
filename = st.session_state[‘selected_file’]
st.write(filename)
folder_path = ‘./docs’
uploaded = os.path.join(folder_path, filename)
pdf_viewer(input=uploaded, width=1000)
trbtl commented 7 months ago

Also, if I select Rerun from the menu it will display the PDF.

trbtl commented 7 months ago

To check my work I set up in a new folder. I installed a fresh virtual environment and pip installed a fresh streamlit and streamlit_pdf_viewer. I then coded a minimumal version of a pdf viewer (see below). It still won't show the pdf until I select Rerun from the menu it will display the PDF.

import streamlit as st
from streamlit_pdf_viewer import pdf_viewer
import os

filename = 'Choosing a Treatment for Kidney Failure - NIDDK.pdf'
st.write(filename)
folder_path = './docs'
uploaded = os.path.join(folder_path, filename)
pdf_viewer(input=uploaded, width=1000)
lfoppiano commented 7 months ago

@trbtl thanks for reporting this issue. It seems related to #35 but I'm surprised that it happens as you pass the width parameter.

Which browser and SO are you using?

trbtl commented 7 months ago

Chrome

Thanks Bob

From: Luca Foppiano @.> Sent: Sunday, February 25, 2024 2:49 PM To: lfoppiano/streamlit-pdf-viewer @.> Cc: mail @.>; Mention @.> Subject: Re: [lfoppiano/streamlit-pdf-viewer] pdf not showing (Issue #37)

@trbtlhttps://github.com/trbtl thanks for reporting this issue. It seems related to #35https://github.com/lfoppiano/streamlit-pdf-viewer/issues/35 but I'm surprised that it happens as you pass the width parameter.

Which browser and SO are you using?

— Reply to this email directly, view it on GitHubhttps://github.com/lfoppiano/streamlit-pdf-viewer/issues/37#issuecomment-1963088750, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BA2JSE4U3L2ZJGVUGPIS72TYVO5V5AVCNFSM6AAAAABDYMY2YSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTGA4DQNZVGA. You are receiving this because you were mentioned.Message ID: @.**@.>>

lfoppiano commented 7 months ago

This is likely a regression from #28. If you revert to version 0.0.7 it should work, however, the application will use more CPU because of an infinite loop in the frontend.

trbtl commented 7 months ago

That works! What is it about version 0.0.8 that is a problem with chromium browsers? Will this be an issue going forward?

Thanks Bob

From: Luca Foppiano @.> Sent: Sunday, February 25, 2024 4:15 PM To: lfoppiano/streamlit-pdf-viewer @.> Cc: mail @.>; Mention @.> Subject: Re: [lfoppiano/streamlit-pdf-viewer] pdf not showing (Issue #37)

This is likely a regression from #28https://github.com/lfoppiano/streamlit-pdf-viewer/issues/28. If you revert to version 0.0.7 it should work, however, the application will use more CPU because of an infinite loop in the frontend.

— Reply to this email directly, view it on GitHubhttps://github.com/lfoppiano/streamlit-pdf-viewer/issues/37#issuecomment-1963116949, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BA2JSEZI2NEWMZHEFCPHWYLYVPHZXAVCNFSM6AAAAABDYMY2YSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTGEYTMOJUHE. You are receiving this because you were mentioned.Message ID: @.**@.>>

lfoppiano commented 7 months ago

@trbtl Unfortunately, the issue is not related to the browser, it's a regression from #28 which we did not notice in our demo tests. We are working already on a solution, and we will have integration tests trying to spot those situations in future. Leave this issue open and we will update you when a new release will solve this issue.

trbtl commented 7 months ago

Thank you so much! I don’t think I’ve ever had such quick and helpful response. Keep up the good work.

Thanks Bob

From: Luca Foppiano @.> Sent: Sunday, February 25, 2024 4:44 PM To: lfoppiano/streamlit-pdf-viewer @.> Cc: mail @.>; Mention @.> Subject: Re: [lfoppiano/streamlit-pdf-viewer] pdf not showing (Issue #37)

@trbtlhttps://github.com/trbtl Unfortunately, the issue is not related to the browser, it's a regression from #28https://github.com/lfoppiano/streamlit-pdf-viewer/issues/28 which we did not notice in our demo tests. We are working already on a solution, and we will have integration tests trying to spot those situations in future. Leave this issue open and we will update you when a new release will solve this issue.

— Reply to this email directly, view it on GitHubhttps://github.com/lfoppiano/streamlit-pdf-viewer/issues/37#issuecomment-1963133775, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BA2JSE5BEEAHEIGURIOHGDDYVPLFBAVCNFSM6AAAAABDYMY2YSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTGEZTGNZXGU. You are receiving this because you were mentioned.Message ID: @.**@.>>

trbtl commented 6 months ago

Now the problem is a problem with displaying a pdf in Streamlit Cloud. The pdf displays correctly when I run it locally, but no luck with displaying it on Streamlit Cloud. I opened an issue #43 - https://github.com/lfoppiano/streamlit-pdf-viewer/issues/43 Any ideas?

Thanks Bob

From: Bob Cole @.> Sent: Sunday, February 25, 2024 4:35 PM To: lfoppiano/streamlit-pdf-viewer @.>; lfoppiano/streamlit-pdf-viewer @.> Cc: mail @.>; Mention @.***> Subject: RE: [lfoppiano/streamlit-pdf-viewer] pdf not showing (Issue #37)

That works! What is it about version 0.0.8 that is a problem with chromium browsers? Will this be an issue going forward?

Thanks Bob

From: Luca Foppiano @.**@.>> Sent: Sunday, February 25, 2024 4:15 PM To: lfoppiano/streamlit-pdf-viewer @.**@.>> Cc: mail @.**@.>>; Mention @.**@.>> Subject: Re: [lfoppiano/streamlit-pdf-viewer] pdf not showing (Issue #37)

This is likely a regression from #28https://github.com/lfoppiano/streamlit-pdf-viewer/issues/28. If you revert to version 0.0.7 it should work, however, the application will use more CPU because of an infinite loop in the frontend.

— Reply to this email directly, view it on GitHubhttps://github.com/lfoppiano/streamlit-pdf-viewer/issues/37#issuecomment-1963116949, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BA2JSEZI2NEWMZHEFCPHWYLYVPHZXAVCNFSM6AAAAABDYMY2YSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTGEYTMOJUHE. You are receiving this because you were mentioned.Message ID: @.**@.>>

lfoppiano commented 6 months ago

I just published version 0.0.9 which should solve the issues you've reported.

At your earliest convenience, could you give it a try and let me know?