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 dashDataTables is easier (something I need for my project).
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.
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
I am also working on adding dash table with data bars in streamlit but it is not showing styling this way. Can you please help me?
I am trying to display data bar in table and then further in streamlit Conditional Formatting | Dash for Python Documentation | Plotly