Run ExplainerDashboard inside a streamlit application

Question:

I want to run the ExplainerDashboard inside a Streamlit application. Is there a way I can do that? I have tried all modes of ExplainerDashboard run() function but it still isn’t working for me.

Here is what I have done so far but it doesn’t work.

from sklearn.model_selection import train_test_split
import streamlit as st
import pandas as pd
from explainerdashboard import ClassifierExplainer, ExplainerDashboard
from sklearn.linear_model import LogisticRegression 
from sklearn.model_selection import train_test_split

def app():
    
    st.title("This is the machine learning page")
    st.markdown("redirect to my [app](https://github.com/prakharrathi25/data-storyteller/blob/main/app.py)")


    st.write("This is an example of a Streamlit app - machine learning")
    
    # show the same data in the machine learning page 
    data = pd.read_csv('data/iris.csv')
    st.dataframe(data)

    # Divide X and y 
    X = data[['A', 'B', 'C', 'D']]
    y = data['E']

    # Convert y to labels 
    y = y.map({'Iris-setosa': 0, 'Iris-versicolor': 1, 'Iris-virginica': 2})

    X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8)

    model = LogisticRegression()
    model.fit(X_train, y_train)

    st.write(model) # the code only runs till here

    explainer = ClassifierExplainer(model, X_test, y_test)
    ExplainerDashboard(explainer).run(mode='external')

    st.markdown("Check out the [explainer dashboard](http://192.168.1.3:8050/)")


Asked By: Prakhar Rathi

||

Answers:

Run the dashboard normally, and run streamlit loading the url of dashboard as iframe in streamlit app.

  1. run dashboard
  2. Get dashboard local url
  3. run streamlit

Streamlit code

def app():
    """
    Set appearance to wide mode.
    """
    st.title("This is the machine learning page")

    dashboardurl = 'http://127.0.0.1:8050/'
    st.components.v1.iframe(dashboardurl, width=None, height=900, scrolling=True)

Image

enter image description here

Answered By: ferdy