How to display '<IPython.core.display.HTML object>' with streamlit components?


I am working on a binary text-classifier and I wanted to display the weights of the classifier using eli5, specifically eli5.show_weights().
show_weights() returns the following object: <IPython.core.display.HTML object>.

I was my understanding that I should be able to display this HTML-object in a streamlit dashboard. However, every time I try it, I get the following error message:
Traceback (most recent call last):

File “”, line 1, in

File “C:\Users\mkp\Anaconda3\lib\site-packages\streamlit\”, line 127, in wrapped_method
return dg._enqueue_new_element_delta(marshall_element, delta_type, last_index)

File “C:\Users\mkp\Anaconda3\lib\site-packages\streamlit\”, line 398, in _enqueue_new_element_delta
rv = marshall_element(

File “C:\Users\mkp\Anaconda3\lib\site-packages\streamlit\”, line 125, in marshall_element
return method(dg, element, *args, **kwargs)

File “C:\Users\mkp\Anaconda3\lib\site-packages\streamlit\”, line 1612, in _html

AttributeError: iframe

If I try the example from streamlit’s docs, I get the same error message:
Tweets by streamlit


Hi @Prelon, welcome to the forum :wave:

You have to pass raw html to streamlit in this case.

from streamlit import components

html_object = show_weights(clf, vec=vec)

raw_html = html_object._repr_html_()



Hi @Jonathan_Rhone,

Thank you so much for your reply - highly appreciated!

Sorry for the late reply, I’ve just come home from vacation.

Your answer worked to some extent - however… If I try show_prediction it only visualize the weights and not the highlighted text like shown below:

This exact line works like a charm in a jupyter notebook and returns the output above:

    eli5.show_prediction(clf, text['preprocessed_text'].values[0], vec=vec, top=20,feature_names = vec.get_feature_names(), show_feature_values=True)

What am I doing wrong?

Hi @Prelon,

Could you provide sample code that I can copy/paste and run to repro what you’re seeing?

1 Like

Nevermind, @Jonathan_Rhone.
I found out that it was due to different versions of sklearn on two of my devices. Classic.

1 Like