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