"streamlit_javascript" does not work on Streamlit Cloud

The same code works locally, but when deployed on Streamlit Cloud, it’s unable to read information from the local cache.

import streamlit as st
from streamlit_javascript import st_javascript
import time

test = st.text_input("input:")

if st.button("Set"):
        f"localStorage.setItem('test123', JSON.stringify({test}));")

if st.button("load"):
    st.write(f"Load test")
    v = st_javascript(f"JSON.parse(localStorage.getItem('test123'));")

This is on localhost:

This is on https://gpt-open.streamlit.app/test:

Hi @KamiPasi

There seems to be a related post here that provides a working implementation, could you see if you can adapt that and if it works for you: Interact with local storage · Issue #5105 · streamlit/streamlit · GitHub

It was from this post that I learned about streamlit-javascript. It works on my local computer, but when I deployed it to the Streamlit Cloud, I couldn’t read data from the local cache.

After changing it to time.sleep(3), it succeeded.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.