This is how to use Sweetviz with Streamlit

If you’ve created a Streamlit component with React you’ll have a frontend/public folder from which to serve static HTML files. I figured if I could generate the static analysis output of Sweetviz into that folder, then it would be easy to display it in my Streamlit app. Sure enough, it is very easy:

import streamlit as st
import streamlit.components.v1 as components
import pandas as pd
# https://pypi.org/project/sweetviz/
# https://github.com/fbdesignpro/sweetviz
import sweetviz as sv

def app(title=None):

    st.title(title)
    df = pd.read_csv('./data/Time_Series.csv')
    st.write(df.head())

    skip_columns_years = [str(y) for y in range(2016, 2026)]
    skip_columns_time_series = ['Date of last update', 'Databank code', 'Scenario', 'Location code', 'Indicator code'] + skip_columns_years

    # Use the analysis function from sweetviz module to create a 'DataframeReport' object.
    analysis = sv.analyze([df,'EDA'], feat_cfg=sv.FeatureConfig(
        skip=skip_columns_time_series,
        force_text=[]), target_feat=None)

    # Render the output on a web page.
    analysis.show_html(filepath='./frontend/public/EDA.html', open_browser=False, layout='vertical', scale=1.0)
    components.iframe(src='http://localhost:3001/EDA.html', width=1100, height=1200, scrolling=True)

app(title='Sweet Visualization')

I’m loading a CSV of time series data (with annual data for 2016-2025). The year/value columns and a few others are ignored in the EDA analysis (skip_columns_years, skip_columns_time_series). Sweetviz generates its analysis output HTML file into './frontend/public/EDA.html' (i.e., the component’s static content folder). analysis.show_html() is configured to not open the analysis itself in a separate browser window. Finally, I display the static HTML file with components.iframe()!

There are just two lines of important Sweetviz code and in combination with Streamlit you can achieve something pretty powerful for your EDA tasks.

P.S. From the docs: Pandas-Profiling was the original inspiration for this project.

4 Likes