Can I display Dash DataTables on Streamlit?

I am trying to display a table/dataframe built with dash_table from the dash package on my Streamlit dashboard, but I am getting empty tables/dataframes.

Presumably this is because st.table() and st.dataframe() do not take DataTable objects as input.

Here is my code:

plot_positions = dash_table.DataTable(
            id='Positions',
            columns=[{"name": i, "id": i} for i in df.columns],
            data=df.to_dict('records'),
        )
st.dataframe(plot_positions)

How can I/what’s the proper way to display a DataTable object on Streamlit?

I am using dash instead of plotly.go.Table because conditional formatting on with dash DataTables is easier (something I need for my project).

1 Like

Hi @Luiz_Scheuer,

st.dataframe takes any of the following: pandas.DataFrame, pandas.Styler, pyarrow.Table, numpy.ndarray, Iterable, dict, or None. You’ll probably want to convert your DataTable to one of the above formats.

Hi @Luiz_Scheuer :wave:

Here’s one method. Pass the DataTable’s .data attribute to st.dataframe like so:

import pandas as pd
from dash import Dash, dash_table
import streamlit as st

raw_df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/solar.csv"
)

# Create a Dash DataTable
df = dash_table.DataTable(
    raw_df.to_dict("records"), [{"name": i, "id": i} for i in raw_df.columns]
)

# Display Dash DataTable in Streamlit
st.dataframe(df.data) # Pass the DataTable's .data attribute

Best,
Snehan :balloon:

1 Like