The arulesviz library returns an ipywidgets object, which are made for visualize stuff in Jupyter Notebooks; streamlit does not support ipywidgets right out the box.
An alternative is to export the ipywidget object (i.e., the arulesviz figure) into a standalone HTML that can then be added to streamlit as a new component.
Here is the code to get the example from above:
import streamlit as st
from io import StringIO
from ipywidgets.embed import embed_minimal_html
from arulesviz import Arulesviz
"# 🖇 `arulesviz`"
WIDTH = 700
#- Example taken from `https://github.com/lispsil/python-arulesviz/blob/master/examples/groceries.ipynb`"
transactions = 
to_drop = set()
with open('groceries.csv') as f:
for row in f:
q = set(row.strip().split(',')) - to_drop
if len(q) > 1: transactions.append(q)
g = Arulesviz(
transactions, 0.001, 0.3, 12,
products_to_drop=['other vegetables', 'whole milk', 'yogurt', 'root vegetables','fruit/vegetable juice']
fig = g.plot_graph(width=WIDTH, directed=False, charge=-200, link_distance=30)
## Exports the ipywidget to HTML and embeds it to streamlit
with StringIO() as f:
embed_minimal_html(f, [fig], title="Hey!")
fig_html = f.getvalue()
st.components.v1.html(fig_html, width=WIDTH, height=700, scrolling=True)
you will need a version of ipywidgets below 7.7 because of something on the embed_minimal_html function of ipywidgets 8 that does not play along with streamlit.