I am using streamlit and loading data that I would like to put into a table with more customization than is currently offered by st.dataframe and st.table.
Below I use the tabulate package to change my data (after manipulating it with pandas) into an html table. My data is large so not something that I would like to type out. This is shown below with random data.
I then would like to add to the basic html template that is produced with my data things like a custom header and a larger font and a height for the table, however I can't seem to find a way to access the html stored in test2. I can wrap things around it (shown below) but can't get into the which is stored in test2.
Any thoughts on how to add to a tabulated tables output html would be helpful
import tabulate as tb
import streamlit as st
import pandas as pd
import numpy as np
np.random.seed(42)
data = {
'A': np.random.rand(100),
'B': np.random.randint(1, 100, size=100),
'C': np.random.choice(['X', 'Y', 'Z'], size=100)
}
df = pd.DataFrame(data)
test2=tb.tabulate(data, tablefmt='html')
test3 = f'<div style="height: 150; overflow: auto">{test2}</div>'
st.markdown(test3, unsafe_allow_html=True)
tabulatehas optionsheadersandshowindexSource code: tabulate
You can also add
CSSto change itBut you may also use
DataFrameto generateHTMLwithouttabulate.And it may use
df.stylewith many functions to format every cell.This example changes background for
maximalandminimalvalue in columnsAandBFull code: