it seems i am unable to access the CSS variables for the default template colors.
Here is described that i can access them via background-color: var(–text-color);
Can you point out where i am wrong ?
import streamlit as st
@st.dialog("Edit")
def edit_table_data(x):
with st.popover("Edit"):
st.write(f"Editing {x}")
def display_table(table_data, column_formating = None, edit_function=False, has_header = True, header_color = None, alternating_row_colors = False):
modifier = 0 if not edit_function else 1
st.html("""<style> .st-key-rnd_table { display: block;} </style>""")
with st.container(key="rnd_table"):
for j,row in enumerate(table_data):
row_len = len(row) + modifier
if j == 0 and header_color:
style= f"{{background-color: {header_color};}}"
else:
if alternating_row_colors == True and ((j+1) % 2 != 0):
style = f"{{background-color: rgb(240, 242, 246);}}"
else:
style = f"{{background-color: transparent;}}"
with st.container(key=f"row_{j}"):
columns = st.columns(row_len if not column_formating else column_formating)
for i,col in enumerate(row):
columns[i].write(col)
if edit_function and (j != 0 and has_header):
with columns[i+1]:
if st.button("Edit",key=f'edit_{j}'):
edit_function(j)
st.html(f"""<style> .st-key-row_{j} {{ background-color: var(--text-color);}} </style>""") # should give a black/ white bar but just does nothing ?
# st.html(f"""<style> .st-key-row_{j} {{ background-color: green;}} </style>""") -- works nicely
data = [['First', 'Second', 'Third'],
['A', 'B', 'C'],
['D', 'E', 'F'],
['G', 'H', 'I']]
display_table(
data,
edit_function=edit_table_data,
header_color="var(--text-color)",
alternating_row_colors=True,
)
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.