Pivottablejs did not run in streamlit cloud

Sir, please find the code below. It runs perfectly fine locally, but it does not execute in Streamlit Cloud. The compilation is successful; however, after compilation, it presents an error, which you can observe in the error image. Kindly provide me with the appropriate solution. Thank you in advance for your valuable assistance.

see all in link
https://jspage.streamlit.app/

sir this is my code

import streamlit as st
import streamlit.components.v1 as components
import pandas as pd
from pivottablejs import pivot_ui
mdf = pd.DataFrame({“A”: [“foo”, “foo”, “foo”, “foo”, “foo”,
“bar”, “bar”, “bar”, “bar”],
“G”: [‘ADDA01’, ‘ADDAA2’, ‘AFFAA2’, ‘DFFDD3’, ‘DFFDD3’, ‘FDDFF4’, ‘FFFFF5’, ‘TDDTT6’, ‘RRR7’],
“E”: [2, 4, 5, 5, 6, 6, 8, 9, 9]})
t = pivot_ui(mdf)
with open(t.src) as t:
components.html(t.read(), width=900, height=1000, scrolling=True)

this is requirements.txt file
numpy
pandas
seaborn
openpyxl
pivottablejs

see error

If pivottablejs is spinning up a server, this will not work in the cloud. Specifically, the server is probably being started on 0.0.0.0 (localhost) and will not be reachable from your browser (as it would be if everything is running locally).

I apologize, sir. This code was functioning perfectly until last week; however, it is now producing an error this week. I have been using pivottablejs on the Streamlit server for the past four months without any issues, but it is encountering an error this week.

You’re right to highlight this your code runs locally because pivottablejs creates a temporary HTML file, which doesn’t persist or render well on Streamlit Cloud due to sandbox restrictions. Instead, try using streamlit-pivottable or convert the HTML to a string and embed it directly using components.html(). That should make it Streamlit Cloud–friendly.

Thank you very very much for your prompt reply
I kindly request that you send me the sample code for utilizing components.html() in Python Streamlit. As I am new to Streamlit, I would appreciate your guidance on how to implement components.html() in Python using VSCode. Thank you in advance for your valuable assistance.

Assuming your raw HTML is assigned to raw_html:

import base64
import streamlit as st
import streamlit.components.v1 as components
from pivottablejs import pivot_ui

mdf = pd.DataFrame({
    "A": ["foo", "bar", "baz"],
    "G": ["ADDA01", "ADDAA2", "AFFAA2"],
    "E": [2, 4, 5]
})
t = pivot_ui(mdf)
with open(t.src) as t:
    raw_html = t.read()
b4_raw_html = base64.b64encode(raw_html).decode()
src = f"data:text/html;base64,{b64_raw_html}"
components.iframe(src=src, width=900, height=1000, scrolling=True)

This code of mine my help too: This is how to use Sweetviz with Streamlit