Display IPython Content in Streamlit (Pycaret)

Hello everyone

What I would like to achieve is to show the IPython Output of Pycaret in a streamlit app that you can see when you run PyCaret in a JupyterNotebook (setup, compare_models()m etc.) (see screenshot). That would provide the user some feedback on the progress (especially when using compare_models()) and also to have the opportunity to enter an input when needed (e.g. preprocessing data - select data type).
I read in this streamlit post that if you can access the html content of your object, you can show it in streamlit with an html component. (Integrating streamlit and jupyter notebook's IPython.display). This is why I am wondering how to access either the html object or access the IPython runtime display.

my questions
1.) Is this the right approach or is there an easier way to show the interactive results from JupyterNotebook/Pycaret directly in Streamlit?
2.) If this is the right approach, how can I access the html/IPython output from setup(), or compare_models()I have been googling, reading the documentation and went through the source code but I was not able to find something that would help me.

I appreciate any ideas, links and thoughts.
Thank you and kind regards
Chris

Additional links that I found that relate to the topic but did not help me
PyCaret - How to have similar output in Spyder as Jupyter Notebook - Stack Overflow
setting the html parameter in the setup function to turn off the IPython Interactivity.

5 things you are doing wrong in PyCaret | by Moez Ali | Towards Data Science
I found out about the pycaret pull() function. This saves the final result in a dataframe but misses the interactivity (like progress bar, input etc) and is also not available for the setup() function.

Hi @ChrisPeter -

Yes, in general, anything that has a HTML method (which I think it required for Jupyter notebook?) can be displayed as you expect. Usually there is something like _repr_html that you can use.

You are correct though that you don’t get interactivity that way. The best way to handle that would be to lobby the various library owners to add a Streamlit method / build a custom component. At its most basic, those sorts of animations have to finish processing as the method before anything is returned to Streamlit, so there isn’t a good way for us to ‘reach inside’ and get those intermediate steps out.

Best,
Randy

1 Like

Thank you very much for your reply. I really appreciate it!

1 Like