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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.