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 not updating on st.rerun() in prod. #57

Open
JanEricNitschke opened this issue Jul 29, 2024 · 6 comments
Open

PDF Viewer not updating on st.rerun() in prod. #57

JanEricNitschke opened this issue Jul 29, 2024 · 6 comments
Labels
frontend Part related to the Javascript frontend component help wanted Extra attention is needed
Milestone

Comments

@JanEricNitschke
Copy link

I am having real trouble with an extremely weird issue. Running my application locally works fine, both in the normal poetry environment as well as the docker container. However when i host it online some functionality we use to show the next page does not cause the viewer to refresh with the next page despite changing the page that is sent to pages_to_render and calling a st.rerun().

However it does refresh when interacting with unrelated elements that also call st.rerun(). Would love to know if you have an ide where this is coming from and how to fix it.

Cheers

@lfoppiano
Copy link
Owner

Hi @JanEricNitschke,
thanks for reporting this issue. In order to help you I would need some more information.

Do you have the link to the deployed application? And, do you have the code hosted somewhere? Or can you share a working example?

@JanEricNitschke
Copy link
Author

Hi @lfoppiano , thanks for the quick response.

Unfortunately i cant show you the code or application at the moment and it hard to produce a minimal example as the issue is the discrepancy between the local and hosted version (despite docker). I also do not have much experience with streamlit. I understand that that makes it extremely hard to help/debug. I was just hoping that you might have encountered something similar before or just have a gut feeling what could be causing something like that that i could try out on my side.

@JanEricNitschke
Copy link
Author

But i can try to describe the relevant parts a bit:

The code that displays the pdf is

if st.session_state[selected_pdf]:
    pdf_view = st.session_state[selected_pdf]
    display_pdf(pdf_view.content, key="some_key", pages_to_render=[pdf_view.active_page], render_text=True)

And then i have this to move through the pages (this works locally but not deployed)

if st.session_state[selected_pdf]:
    pdf_view = st.session_state[selected_pdf]
    with col_prev:
        if st.button():
            pdf_view.active_page -= 1
            st.rerun()
    with col_num:
        def update_page_number():
            st.session_state[selected_pdf].active_page = st.session_state["temp_page"]
            st.session_state["rerun_needed"] = True

        st.number_input("somelabel", value=pdf_view.active_page, key="temp_page", on_change=update_page_number)
        if st.session_state.get("rerun_needed"):
            st.session_state["rerun_needed"] = False
            st.rerun()

and this to change the pdf shown:

with col_sel:
     for i, pdf_view in enumerate(st.session_state[üdf_kind]):
         if st.button("some_label", key="button_key")
             st.session_state[selected_pdf] = pdf_view
             st.rerun()

@JanEricNitschke
Copy link
Author

I think it might be some sort of race condition as my local machine is significantly better than what I have hosted it on.

@lfoppiano
Copy link
Owner

Thanks. I will try to look at it in the next two weeks. If anything else comes to your mind feel free to comment here.

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

lfoppiano commented Aug 5, 2024

@JanEricNitschke I've released the version 0.0.16 which solves some issues with the viewer.
Could you please give it a try, please specify either width or heigh when you call pdf_viewer.

@lfoppiano lfoppiano added help wanted Extra attention is needed frontend Part related to the Javascript frontend component labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Part related to the Javascript frontend component help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants