Including Pandas Profiling Report in Streamlit

Q1)How to add the pandas profile report and other charts in the streamlit?
As I am starting to explore the streamlit, I have tried this in my editor and got nothing as an output to the pandas profiling report.
How do I add the profiling report ?
Where Can I find the full documentation of all the widgets and controls one can add in streamlit?
Here is my code:

import streamlit as st
import pandas as pd
import pandas_profiling as pf
DATE_COLUMN = 'date/time'
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
            'streamlit-demo-data/uber-raw-data-sep14.csv.gz')


@st.cache
def load_data(nrows):
    data = pd.read_csv(DATA_URL, nrows=nrows)
    def lowercase(x): return str(x).lower()
    data.rename(lowercase, axis='columns', inplace=True)
    data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
    return data


data = load_data(100)
st.subheader('Raw Data')
st.write(data)
x = st.slider('x')
st.write(x, 'Squared is :', x*x)
selectbox_label = st.selectbox('Filter to :', ['lat', 'lon'])
selected_columns = selectbox_label
st.write(data[selected_columns])
report = pf.ProfileReport(data)
st.write(report)
1 Like

Hi @AVI18794

I took a look at it It should be doable as the report can be output in HTML

If you combine this with the ability to write html in markdown

You should be able to create something.

I would also like to create such a thing but i cannot get pandas-profilling to work. I experience the issue reported here https://github.com/pandas-profiling/pandas-profiling/issues/183

Good luck :slight_smile:

1 Like

Well, I wanted to do the same thing as @AVI18794 wanted to

And I tested the @Marc’s advise and modified as the following

profile = df.profile_report()
st.write(profile.html, unsafe_allow_html = True)

However, the result is not that so perfect as using in Jupyter Notebook.

streamlit’ result

Juypter Notebook result

Is there other solution to display pandas profiling in streamlit?

1 Like

Hi @AVI18794 and @jimmy60805

This Pandas Profiling module is awesome! I wasn’t aware of its existence — thanks for sharing it :smiley:

I don’t see a way to show Pandas profiles in Streamlit today, except for the imperfect solution y’all already discovered. The reason for this is that we don’t support passing raw HTML to your app, for security reasons. With raw HTML it would be very easy for malicious code to do things like steal data from the app and send it to an external server. Or steal some credential of yours. And so on.

So we ask users to let us know whenever they hit a road-block like this, so we can implement a secure solution for them.

In this specific case, I think we should just implement support for Pandas profile reports! So I created a feature request for it here. Please subscribe to the linked Github issue to follow up on any progress we make there.

3 Likes

Hi @thiago

Thanks your reply!!!

Wait for your improvement for supporting Pandas-Profiles and thank for all your efforts in developing streamlit :grin:

2 Likes

By running this:
st.markdown(profile.to_html(), unsafe_allow_html=True)

streamlit.version
‘0.62.0’

I actually get parsing error.

Error parsing Markdown or HTML in this string:

<!doctype html><meta name=description content="Profile report generated with the

2 Likes

Hello all,

I was facing the same issue, till i found out a solution.

check here:

Hi guys,
I just started to use Streamlit. I also wanted to use Pandas Profiling to my project. I came to this question, and I solved it.

You need st.components.v1.html to do so:

import pandas-profiling as pp
import streamlit as st
import streamlit.components.v1 as components


df = pd.read_csv()...
report = pp.ProfileReprot(df, title="...").to_html()
components.html(report, height=..., width=...)

Good luck!

3 Likes

Hey @minhlong94,

This is indeed an easy way to render pandas profiling report :smiley:

However I personally had issues with height that doesn’t auto updates. With widgets that can expand, you might either have a height which is too short when widgets are expanded, or a blank area at the bottom of your page when they’re not.

If you come across this problem, my component handles the issue: Pandas Profiling

Hi @okld,
Thank for your comment. Yes I did use your repo initially, but then I had a side problem: the Profile Report was too long, but your repo did not have an option to enable scrolling, so I ended up using st components.
Should I make that a feature request?

1 Like

Oh I see. Please do! I’ll add a new height parameter soon.

Hello @minhlong94,

A new height parameter was added in release 0.1.1.

I resolved the issue from pandas_profiling side.

I changed the silent parameter in to_file() function to False

now the resulting report will be opened in another tab where the user can save the page their own :slight_smile:

here is my code

st.title('Explore a dataset')

file = st.file_uploader("test.csv", type=['csv', 'xlsx'])

df =  pd.read_csv(file)
prof = ProfileReport(df, explorative=True, minimal=True)

output = prof.to_file('output.html', silent=False)```

Hey, you can use the scrolling option in the html method given the height and width size of the widget. I did it in the following manner:

components.html(report, height=1000, width=950,scrolling=True)

2 Likes

Hello @Mahima-ai, indeed I could use this option, but my motivation was to avoid using it and get a seamless integration of profile reports in my apps. Of course if that doesn’t bother you, fixing your own height and using scrolling=True if perfectly fine.

This really works! Thks

does df - dataframe provides any profile_report() functions
I can not able to resolve this issue…
help me how I can resolve it?

code where issue is -
pr = df.profile_report()
st_profile_report(pr)

My imports –
import time

import pandas_profiling

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import streamlit as st

from sklearn.linear_model import LogisticRegression

from sklearn.model_selection import train_test_split

from streamlit_option_menu import option_menu

from streamlit_pandas_profiling import st_profile_report

from pydantic_settings import BaseSettings