Skip to main content

Hi,
I am encountering the following error while using Streamlit-AgGrid in Cognite’s Streamlit:

This link explains the workaround, but I’m not sure how to do the fixing in Cognite.

Could anyone help me and is there a specific version of Streamlit or Streamlit-AgGrid I need to use to avoid this problem?

Thanks in advance for your assistance! 

@norzarifah I’ll check on this with the engineering team and get back to you with an update.


 

Hi,

Sorry for the late reply. What you can do is open the file in the top of your Streamlit app and perform that fix with a .replace. The way I found the path was to first have a very small app with the `streamlit-aggrid` package installed.

Then you can have as the only piece of code

import st_aggrid
st.write(st_aggrid.__file__)

which will show that the path is `/lib/python3.12/site-packages/st_aggrid/init.py`.

We will use this to know where to find the file, but we have to patch it before we import it, so take a note of that path and replace the code with

with open('/lib/python3.12/site-packages/st_aggrid/__init__.py') as f:
contents = f.read()
contents = contents.replace('components.components.MarshallComponentException', 'components.custom_component.MarshallComponentException')
with open('/lib/python3.12/site-packages/st_aggrid/__init__.py', 'w') as f:
f.write(contents)

This will first read the file (see GitHub solution), then replace every occurrence with the wrong line with the correct one and then write the file. Now you can safely import it after.

with open('/lib/python3.12/site-packages/st_aggrid/__init__.py') as f:
contents = f.read()
contents = contents.replace('components.components.MarshallComponentException', 'components.custom_component.MarshallComponentException')
with open('/lib/python3.12/site-packages/st_aggrid/__init__.py', 'w') as f:
f.write(contents)

# Now we can import
import st_aggrid

You may have to refresh the page between the first step (extracting the path) and the second since we cannot have imported the code before patching.

Let me know if this works or if it doesn’t!


Hello, 

The workaround works perfectly! My goal is to use JsCode object for custom rendering of URLs in the AgGrid component. Now everything functions as expected and thank you so much!

 


Reply