Dabl in streamlit

Hello everyone,

I am trying to show the plot generated using dabl library in streamlit app, but with the following code, I am getting only one plot. Can you please help me understand how to show all the plots generated using dabl on streamlit app.

import streamlit as st
import pandas as pd
import dabl

df= pd.read_csv("spambase.csv")
dabl.plot(df, "spam")
st.pyplot()

Hey @tjsxstreamlit :wave:

You may want to try this code:


import streamlit as st
import pandas as pd
import dabl
import matplotlib.pyplot as plt

df = pd.read_csv("spambase.csv")

figures = dabl.plot(df, "spam")

if isinstance(figures, list):
    for fig in figures:
        st.pyplot(fig)
else:
    st.pyplot(figures)

I believe this one should work as expected – Let me know.

Best,
Charly

Thank you Charly.

I tried to implement your logic and got following error:

Ohh I don’t have access to my laptop now to check, but we may need to ensure that the correct type (Figure) is passed to st.pyplot, preventing the “AttributeError.” Something like this might work:

import streamlit as st
import pandas as pd
import dabl
import matplotlib.pyplot as plt

df = pd.read_csv("spambase.csv")

plots = dabl.plot(df, "spam")

if isinstance(plots, list):
    for ax in plots:
        st.pyplot(ax.figure)
else:
    st.pyplot(plots.figure)

Let me know if that solution works. I should be able to have a closer look at the issue shortly once I’m back in front of my screen! :smiling_face:

Best,
Charly

Thank you Charly.

I tried the new code.

Output looks like following

The output of line

plots = dabl.plot(df, "spam")

is as follows:

[<Axes: title={‘center’: ‘Target distribution’}, xlabel=‘count’, ylabel=‘spam’>, [<Figure size 2000x400 with 10 Axes>, array([[<Axes: title={‘center’: ‘0.824’}, xlabel=‘word_freq_remove’, ylabel=‘char_freq_$’>,
<Axes: title={‘center’: ‘0.819’}, xlabel=‘word_freq_hp’, ylabel=‘capital_run_lengt…’>,
<Axes: title={‘center’: ‘0.813’}, xlabel=‘char_freq_$’, ylabel=‘word_freq_free’>,
<Axes: title={‘center’: ‘0.801’}, xlabel=‘word_freq_your’, ylabel=‘word_freq_hp’>]],
dtype=object), <Figure size 1600x400 with 4 Axes>, <Figure size 640x480 with 1 Axes>], None]

I also tried couple ways to iterate over it, but still struggling to find solution. Please let me know your thoughts.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.